Search This Blog
Showing posts with label Qt. Show all posts
Showing posts with label Qt. Show all posts
Sunday, February 10, 2013
BCD Adder (Binary-coded decimal)
Binary Code Decimal (BCD) Adder.
This is a tool that helps you add two decimals as BCD.
Why is BCD adder useful?
Double and Float sometimes do not meet the requirement of precision. For example, you cannot hold more than 17 digits in double.
With this BCD adder, you can add numbers with 10^18 digits!
Source: https://github.com/crystalcoding/HappyHacking/tree/master/BCD/bcd_gui
Download (windows binary): http://dl.dropbox.com/u/58798915/release-BCD-v0.9.zip
Tuesday, December 6, 2011
Qt Djvu, Short Template to Extract Target Line in Current Directory
It's a boilerplate for reading and parsing files.
Just throw in your "process" interface that can do
all the heavy duty work. The code can:
1. read all files in the current directory
2. extract all lines which contain http://
http://code.google.com/p/mixtools/source/browse/trunk/qt/extract_url_in_files.cpp
Saturday, November 7, 2009
Thursday, November 5, 2009
Qt, Understand The UI Designer
QtCreator uses a very cleaver way to separate the GUI part of your widget through
1. Composition
2. Namespace
(This two steps avoid the inheritance)
In essence,
1. The generated UI class can help generate all GUI-widgets for you (button, textline)
2. The generated UI class has a setupUi method (taking your non-gui widget as an argument),
and the method will use your non-gui widget as the single parent of all the auto-generated widgets. (very cleaver!)
3. In your non-gui widget constructor,
a. you generate a new UI class
b. call setupUi
4. but now, how do you refer to the auto-generated widgets created in the Ui class?
No problem! remember the Ui class is also a "member" of your non-gui widget.
5. So you can call connect, layout etc. to interact with your Ui class.
6. In the destructor of your non-gui widget, it can free the memory (delete ui) when your non-gui widget is dead or out of scope.
1. Composition
2. Namespace
(This two steps avoid the inheritance)
In essence,
1. The generated UI class can help generate all GUI-widgets for you (button, textline)
2. The generated UI class has a setupUi method (taking your non-gui widget as an argument),
and the method will use your non-gui widget as the single parent of all the auto-generated widgets. (very cleaver!)
3. In your non-gui widget constructor,
a. you generate a new UI class
b. call setupUi
4. but now, how do you refer to the auto-generated widgets created in the Ui class?
No problem! remember the Ui class is also a "member" of your non-gui widget.
5. So you can call connect, layout etc. to interact with your Ui class.
6. In the destructor of your non-gui widget, it can free the memory (delete ui) when your non-gui widget is dead or out of scope.
Friday, September 11, 2009
Qt, Qt's Build System
qmake -- creates platform specific make file for your platform. Then you can run your native compiler later with your generated make file. Make sure you have a .pro (Qt's project file). It is a configuration file for qmake. E.g. telling the name of the your source file, what Qt module you need (QtNetwork, QtGui, etc...).
moc -- meta object compiler convert signal/slot into standard C++ file.
uic -- creates header files for .ui designer file
rcc -- process the .qrc resource file
moc -- meta object compiler convert signal/slot into standard C++ file.
uic -- creates header files for .ui designer file
rcc -- process the .qrc resource file
Monday, September 7, 2009
Qt, Install Qt Creator in FreeBSD
Qt Creator, a great Qt IDE for C/C++ programming, is officially supported by FreeBSD! This is such a wonderful news! We can compile and install Qt Creator simply using the port collection. (Aug 19, 2009)
Just do:
Just do:
cd /usr/ports/devel/qtcreator/ && make install clean
Make sure you install the right gdb, if your default gdb (/usr/bin/gdb) does not work with QtCreator. And tell Qt Creator to use the right debugger (e.g. /usr/local/bin/gdb66)
cd /usr/ports/devel/gdb6/ && make install clean
Sunday, August 30, 2009
Qt LGPL with Closed Source Software
Using Qt enables the software to be closed source when you "redistribute" it. (It is an important concept. E.g., Google uses GPL Linux kernel "internally" to avoid licensing issue")
So, with Qt's LGPL:
So, with Qt's LGPL:
- Dynamically link the Qt library, with your source code closed.
- The installer can download the Qt library if needed.
- If you modify the Qt library, you must open up the change.
- You might need to provide your object file. (so people can re-link with the Qt's library)
- Ask a lawyer if you are in a serious business, or the licensing violation can be very expensive.
Sunday, July 19, 2009
Qt Creator Missing lfreetype
Qt cannot compile project under Ubuntu (Linux) because of the error
/usr/bin/ld: cannot find -lfreetype
So the library freetype is missing. Qt Creator requires the development package of fonts. Try install them. In Ubuntu, for example,
apt-get install libglib2.0-dev libSM-dev libxrender-dev libfontconfig-dev libxext-dev
/usr/bin/ld: cannot find -lfreetype
So the library freetype is missing. Qt Creator requires the development package of fonts. Try install them. In Ubuntu, for example,
apt-get install libglib2.0-dev libSM-dev libxrender-dev libfontconfig-dev libxext-dev
Tuesday, June 30, 2009
Qt qobject_cast advantage
qobject_cast is like dynamic_cast; it can cast object inherits from QObject.
The advantage is qobject_cast does not require RTTI support
To use it, make sure Q_OBJECT macro is included. Or the return type is undefined.
StackedWidget *stackedWidget = qobject_cast(parent());
if(stackedWidget != 0)
//do something
The advantage is qobject_cast does not require RTTI support
To use it, make sure Q_OBJECT macro is included. Or the return type is undefined.
StackedWidget *stackedWidget = qobject_cast
if(stackedWidget != 0)
//do something
Sunday, June 28, 2009
Qt Shopping List with ListWidget
- Print PDF with QPainter::drawText. Remember to set the coordinate correctly.
- Remeber to set the margin for the gridLayout
Qt Debuging Tips
Output:
- qDebug() : e.g. qDebug() << "Stuff:" <<>
- qCritical(): e.g. qCritical("no more memory");
- qFatal();
- qWarning()
- Q_ASSERT()
- Q_ASSERT_X(): this can print the line where assertion fail
- Q_CHECK_PTR()
- error like "vtbl, _vtbl": this might be related to meta-object compiler, check if using Q_OBJECT correctly, make sure the signal/slot syntax (declaration/implementation), and re-run qmake.
Qt S60 Video
Lessons learn from this video:
http://labs.trolltech.com/blogs/2009/06/25/the-new-pre-release-of-qt-for-s60-is-there/
- In QDesigner, select all widget and group them with layout.
- listWidget is handy.
- window.showMaximized()
- he types very fast and no error
http://labs.trolltech.com/blogs/2009/06/25/the-new-pre-release-of-qt-for-s60-is-there/
Saturday, June 27, 2009
Qt Remove * from a string

- remove string
- auto copy to clipboard
QClipboard *clipboard = QApplication::clipboard();
QString input = clipboard->text();
ui->inputBrowser->setPlainText(input);
QString output = "";
foreach(QChar c, input)
{
if ( c != '*') output += c;
}
ui->outputBrowser->setPlainText(output);
clipboard->setText(output);
source: http://code.google.com/p/mixtools/source/browse/#svn/trunk/qt/kill_stars
Qt Tutorial Notes

source : http://code.google.com/p/mixtools/source/browse/#svn/trunk/qt/tutorial/tutorial
http://doc.trolltech.com/4.3/tutorial.html
T4:
- qApp is a global variable
- Put widget on heap, so Qt can manage the memory for you
- treat layout as the parent of widgets being enclosed
- How to overflow?
- Remember to show() the widget
- setLayout() takes a "pointer" as the argument
- qRand() returns a value between 0 and RAND_MAX (defined in
and ) - check out more global variable in Qt: http://doc.trolltech.com/4.2/qtglobal.html
- Signal can connect to signal: so you fire another signal.
- Two ways to fire a signal: 1. signal connect to signal 2. directly fire it with emit
- Cannot treat signal as slot
- Signal is automatically generated by MOC (meta-object compiler), so do not implement it yourself, or you will get duplicate definition.
- The Q_OBJECT macro must be used in all subclass of QObject, or the signal/slot will not work. Put the Q_OBJECT in the header file, and put the .h file in .pro file. This way qmake can search source and header files for the Q_Object macro. It will generate build instruction for moc.
- slots can be public, protected, and private
- To declare signal, just do "signals:"
- setFocus()
- setFocusProxy()
- QString::Number() convert number to string
- use "&" to set the button shortcut with Alt
- Understand The Coordinate System of Qt
- QRect: upper-left + width + height
- drawPie: 0 is 3 o'clock, and draws counter-clockwise
- QPainter::rotate(): on coordinate, and counter-clockwise
- QTimer::start(int millisecs interval), stop(), isActive()
QTimer::singleShot(600000, &app, SLOT(quit()));
- Understand save() and restore()
Thursday, June 25, 2009
Qt Auto Resize with Qt Designer
If the Qt designer does not seem to handle the resizing of your widgets when running the application, check the following:
we re-set the layout using ui's layout.
Now the widgets inside the layout can be auto-resize in the Qt Designer.
Convince yourself that all the GUI work should be taken care of by the Designer, if you are using it. Try not to alter the code generated by the Qt Designer (the ui header file). The generated file will be overwritten next time you make change, and that's inconvenient. Unless you really want to handle the resizing yourself, do not implement the resizeEvent. Your code might break i n the future on different machine with different resolution.
- To make a widget auto-sizable by itself, it needs to be placed in the layout.
- Call the setLayout(top_most_layout_from_the_designer) at the place where you use the designer's code (the place where you call setupUi())
e.g. ui->setupUi(this);
setLayout(ui->verticalLayout_2);
we re-set the layout using ui's layout.
Now the widgets inside the layout can be auto-resize in the Qt Designer.
Convince yourself that all the GUI work should be taken care of by the Designer, if you are using it. Try not to alter the code generated by the Qt Designer (the ui header file). The generated file will be overwritten next time you make change, and that's inconvenient. Unless you really want to handle the resizing yourself, do not implement the resizeEvent. Your code might break i n the future on different machine with different resolution.
Wednesday, June 24, 2009
Qt Transparent Background on Widget

It is very easy to make the Qt's widget transparent.
source code : https://github.com/crystalcoding/HappyHacking/tree/master/qt/mama-win
this->setWindowOpacity(0.5); //Make the widget half-transparent
For X11, Qt needs a composition manager. For Windows, it will just work. This method is available for widget or subclass of widget. Undermodule QtGui
Monday, June 22, 2009
Qt deployment with Qt Creator

The installation or deployment of Qt Application with shared library, it just needs to:
- Copy the .exe file
- And put the required .dll file in the same directory of your .exe file (e.g. QtCore.dll, QtNetwork.dll)
The procedure entry point _Z21qRegisterResourceDataiPKhS0_S0 could not be located in the dynamic link library QtCore4.dll
The weird thing is that QtCore4.dll is in the same directory of the .exe file. So what is the error? Just as it said, the QtCore4.dll does not contain the symbol!
Solution: make sure to copy the right QtCore4.dll
- Search the Qt SDK install directory, find the RIGHT QtCore4.dll
- In this specific example, do not get the QtCore4.dll under C:\Qt\2009.02\bin,
but in the Qt directory. E.g. C:\Qt\2009.02\qt\bin - Find the QtCore4.dll and QtGui4.dll there, and mingwm10.dll might be needed there if this is a LGPL version.
Try ldd command, this cool program list all the dependencies for your executable
For example, ldd your_program_ , it might output
libQtCore.so.4 => /usr/local/lib/qt4/libQtCore.so.4 (0x800648000)
libz.so.5 => /lib/libz.so.5 (0x80099e000)
libgthread-2.0.so.0 => /usr/local/lib/libgthread-2.0.so.0 (0x800ab2000)
libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x800bb6000)
libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x800d71000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x800f6b000)
libm.so.5 => /lib/libm.so.5 (0x801176000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801296000)
libthr.so.3 => /lib/libthr.so.3 (0x8013a4000)
libc.so.7 => /lib/libc.so.7 (0x8014bc000)
libz.so.4 => /lib/libz.so.4 (0x8016f5000)
libintl.so.8 => /usr/local/lib/libintl.so.8 (0x801809000)
libpcre.so.0 => /usr/local/lib/libpcre.so.0 (0x801912000)
Qt Internationalization

- Add translation file to myapp.pro file.
e.g. TRANSLATION = app_de.ts - Run lupdate on the .pro file (in cmd prompt/console) to generate translation sources in XML-based format. lupdate will generate the .ts file for you.
e.g. lupdate myapp.pro - Run Linquist to load the .ts file.
Put translation strings of your choices there, and then Ctrl+Enter to accept each string. - Generate the binary translation file (.qm), so that you can load it at run time.
lrelease myapp.pro - In your code, create a QTranslator object, QTranslator.load(your .qm file), and then QApplication.installTranslator(your QTranslator object)
Qt Mama Assistant
A program that can easily launch browser to talk to the Internet.
Source Code:
http://code.google.com/p/mixtools/source/browse/#svn/trunk/qt/mama
Source Code:
http://code.google.com/p/mixtools/source/browse/#svn/trunk/qt/mama
Subscribe to:
Posts (Atom)




