Qt
Uses
- http://www.omgubuntu.co.uk/2013/03/unity-next-project-announced
- RStudio is written in the C++ programming language and uses the Qt framework for its graphical user interface. See http://en.wikipedia.org/wiki/RStudio, http://support.rstudio.org/help/discussions/suggestions/3154-rstudio-and-qt-5 and Linux platform or Windows platform.
- Qt is used in a lot of places. See some example in wikipedia. Some famous ones are Mathematica, DreamWorks, Google Earth, HP, KDE, LyX, Roku TV box, Samsung, Skype, Ubuntu, VirtualBox, VLC, Volvo, Propeller GCC IDE, Texmaker, etc. I guess 'Glucore Omics Explorer' was also made from Qt; see LinkedIn.
- 10 Qt use cases “we” didn’t know
- Win32Image: build requirement: 1. MinGW (20120426 from http://mingw.org) 2. Qt for Windows SDK (currently using 4.8.4 mingw from http://qt-project.org)
Download of 4.x and 5.x version
http://download.qt-project.org/official_releases/
For example, the source code for 5.0.1 can be downloaded from http://download.qt-project.org/official_releases/qt/5.0/5.0.1/single/
Transition of Qt 4.x to 5
http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5
How to distribute Qt application
In my first example of GUI with button & label, I need to put 7 dll files in the same exe directory.
- icudt49.dll (17MB)
- icuin49.dll (1.3MB)
- icuuc49.dll (1MB)
- Qt5Cored.dll (7MB)
- Qt5Guid.dll (5.5MB)
- Qt5Widgets.dll (4MB)
- Qt5Widgetsd.dll (7.5MB)
Google: how to reploy application on windows, how to build qt contains all dll static on windows
- http://qt-project.org/wiki/Build_Standalone_Qt_Application_for_Windows
- http://qt-project.org/doc/qt-4.8/deployment-windows.html
- http://qt-project.org/wiki/How_to_build_a_static_Qt_version_for_Windows_with_gcc
- http://stackoverflow.com/questions/15153910/qt-build-to-a-single-exe-file-without-dlls
- http://yjyao.com/2011/02/how-to-deploy-your-qt-application.html
How to Build static Qt on Windows
- http://www.qtcentre.org/wiki/index.php?title=Building_static_Qt_on_Windows
- http://stackoverflow.com/questions/14932315/how-to-compile-qt-5-0-1-static-or-dynamic-on-vs2010-or-vs2012-express-under-wind
- http://stackoverflow.com/questions/14870272/qt-error-while-compiling-qt-5-0-1-on-windows-visual-studio-2010-vs2010
- Google: Qt 5.0 windows build static visual studio 2010 QMAKESPEC
- I can only succeed running configure command from Qt 4.8.4. See also http://qt-project.org/doc/qt-4.8/install-win.html.
- OpenGL: Qt uses OpenGL as cross-platform accelerated graphics API. On windows, some PC do not have OpenGL installed, so for those Qt ships linked against ANGLE which only provides OpenGL ES 2 support by implementing it on top of DirectX 9. See the forum. The instruction about graphical driver is shown on here. That is, we want to install DirectX SDK
My experience based on Qt 4.8.4
- Download and install Perl (no need for python, ruby for Qt 4.8).
- Unzip source file in zip format and put it under C:\Qt
- Rename C:\Qt\qt-everywhere-opensource-src-4.8.4 to C:\Qt\4.8.4
- Open c:\Qt\4.8.4\mkspecs\win32-msvc2010\qmake.conf and change QMAKE_CFLAGS_RELEASE according to the page ?
- Change PATH variable and add C:\Qt\4.8.4\bin.
- Open Visual Studio command prompt and
cd C:\Qt\4.8.4 configure -platform win32-msvc2010 -static -release nmake sub-src
My experience based on Qt 5.0.2
- See the instruction on Git
- read ReadME file to download Perl, Python and Ruby. Make sure the executable path in in PATH env variable.
- Download/Install Windows SDK 7.1 (for Windows 7) or 8 (for Windows 8).
- OpenGL (NOT optional): DirectX SDK The 6/7/2010 version is about 572MB. This will be installed to C:\Program Files (x86)\Microsoft DirectX SDK(June 2010) directory. (The precompiled Qt is built against ANGLE which provides OpenGL ES 2.0 support. ANGLE allows Windows users to run OpenGL ES 2.0 content by translating OpenGL ES 2.0 API calls to DirectX 9 API calls) I actually got an error of Error code S1023 when I installed DirectX SDK. See the solution here/Basically uninstall x86 & x64 VC2010 Redistr and install DirectX SDK and then re-install x86 & x64 VC2010 Redistr.
- modify mkspecs by searching qmake.conf. It was found in C:\Qt\qt-everwhere-opensource-src-5.0.2\qtbase\mkspecs\win32-msvc2010
- configure -static -release -platform win32-msvc2010 -opengl desktop
Install Qt on Ubuntu
It is also necessary to follow qt-project.org/wiki/install_Qt_5_on_Ubuntu to install g++ and OpenGL libraries. Note the last one is what I added to resolve the error of cannot finding -lGL; check Compile Qt 4.7 on Ubuntu 10.10.
sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev
If Qt Creator was installed (eg from binary installer of Qt 5.1.0), then it can be launched by
~/Qt5.1.0/Tools/QtCreator/bin/qtcreator
Qt 5.1.0
Straight forward. Just use 'chmod +x' to make the download file executable and then run the executable file.
./qt-linux-opensource-5.1.0-x86_64-offline.run
At the end, the qmake program is available under ~/Qt5.1.0/5.1.0/gcc_64/bin/qmake.
Qt 4.x.x
Method 1. Use apt-get install approach. See http://www.wikihow.com/Install-Qt-SDK-on-Ubuntu-Linux
sudo apt-get install qt4-dev-tools
At the time of writing (tested on Linux Mint 15), the qmake is 4.5.2 (the Qt website offers 4.8.5).
Method 2. Manually compile it. We also need to do 'apt-get install libxext-dev' to resolve an error that 'basic XLib functionality test failed'.
Qt Creator
- Multiple version of Qt library
- Keyboard shortcuts:
- Ctrl + Click the symbol - move to the definition or the declaration of a symbol.
- Click a symbol + Right click + Follow the symbol under cursor - move to the definition
- The default build directory is parallel to the folder of source code which is a pain if there is a same project name. A better default build directory should be under the source code folder. To change the default setting, go to Tools -> Options -> Build and Run -> Remove "../" from the Default build directory value "../build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}". The project name is determined by Qt project file XXXX.pro.
Qt Tutorial
- http://qt-project.org/doc/qt-4.8/tutorials.html
- http://www.zetcode.com/gui/qt4/ This website contains tutorials of GUI programming by many different languages.
- Lots of examples from codeprogress.com
- Lots of examples from java2s.com
- Qt4 tutorial for absolute beginner
- Using Qt designer from KDE.org
- Qt 5 OpenGL https://www.youtube.com/watch?v=GYa5DLV6ADQ&list=PLizsthdRd0YzA1a8iIRT-c3YPnT5v3Zxw
- 106 Qt programming videos on youtube from VoidRealms
- Qt mouse even on QLabel by Saeed Ghoassy OR http://www.codeprogress.com/cpp/libraries/qt/qtClasses.php?item=QMouseEvent
- Qt C++ drawing mouse event by redbear8174
- Qt create custom widget, repaint(), etc
- Qt + histogram, scatterplot, contour plot,... by -http://qwt.sourceforge.net/ Qwt] See forum
- Forum about heatmap http://www.qtcentre.org/threads/45776-Using-Qt-to-display-a-interactive-heatmap
- Search http://code.google.com/ to find projects based on Qt. Other hosting sites includes sourceforge.org, githumb,... See wikipedia web site.
- sourceforge
Simple Test
To quickly test whether the Qt was built successfully, we can
- On the VS command prompt (the test.cpp can be generated from http://www.zetcode.com/gui/qt4/introduction/)
cd c:\Qt mkdir example cd example notepad test.cpp set PATH=%PATH%;C:\QT\4.8.4\bin qmake -project qmake nmake
If everything went well, we will obtain the executable file under release folder. That is, we can run the executable file by
release\example.exe
Qt-Apps.org
http://qt-apps.org/ is a good source to find open source projects based on Qt.
Graphics
- 2d transformation (works, but kind of simple ...)
- EasyPaint (Poland langauge)
- Boat scenario (cannot compile)
- Q diagram (cannot compile)
Scientific
- Unipro UGENE (cannot compile)
- arrowmatcher (not English)
- QtiPlot (require Python)
- MIFit (require Python)
- Tulip (no .pro file, use 'make')
Qt Widget
C++ basics
See C++ tutorial.
- Use dot (.) to refer to any public member of a class.
- Use the arrow operator (->) to refer to a member of an object pointed by a pointer. The label below is a pointer rather than an object but *label is an object.
QLabel *label = new QLabel("ABCDE"); label->show(); // (*label).show();
- Use the operator of scope (::) to set a definition of a class's member function or call a function from some class. For example,
QObject::connect();
means to use connect() function from QObject class.
- The this pointer passed on to the EditDialog sets the parent of the dlg to the list dialog.
EditDialog dlg( this );
Here explains: The keyword this identifies a special type of pointer. Suppose that you create an object named x of class A, and class A has a nonstatic member function f(). If you call the function x.f(), the keyword this in the body of f() stores the address of x..
Qt Basic
- To run Qt from command line, I use
# Open command prompt from Visual Studio 2010 set PATH=C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\bin;%PATH%
Now we can build the project by for example
cd C:\Qt\FQD\Chapter01\plain-cpp qmake -project qmake nmake
The executable will be located under release subfolder.
- Frame (seems to be the same as 'Dock' in Qt's language)
- Dock window/Dock Widget http://qt-project.org/doc/qt-4.8/mainwindows-dockwidgets.html
- 'namespace Ui' in xxxx.h helps to glue classes together.
- Qt widget - Basic widgets, Advanced widgets, Organizer widgets and Abstract widigets.
- Qt class hierarchy diagram http://doc.qt.digia.com/extras/qt43-class-chart.pdf
- QObject vs QWidget vs QMainWindow http://stackoverflow.com/questions/3298792/whats-the-difference-between-qmainwindow-and-qwidget-and-qdialog
- size().width() can get the width of a widget. See http://www.zetcode.com/gui/qt4/customwidget/
- Qt Event System and Event Classes.
- mouseMoveEvent and an example. Once we reimplement mouseMoveEvent(), it will be automatically used.
- Click on a widget and click promote to. Then type a class name.
- Suppose we create a member function in some class. We can declare it in the header file automatically and move focus to the header to finish it: Click on a member function and click Refactor -> Add Definition in xxxx.h
- On the other hand, we can declare a slot of member function in the header file and then Refactor to have it added to xxx.cpp file.
- ui->setupUi(this); or ui.setupUi(this) . See here.
Qt Tricks
- Build the project in a linux environment has two advantages over VS on Windows: 1) the C++ code is more stringent 2) we can run debugging in Qt Creator.
- Mouse location
- Resize a rectangle as window
- Visual large data (million of data)
- Qt repaint() vs update()
- Resize when child resize by using sizeHint() and minimumSizeHint.
- Set main window initial position
- Qt5 is complaining 'QApplication: No such file or directory ...'. The solution is to add
QT += widgets
to your .pro file.