Qt: Difference between revisions

From 太極
Jump to navigation Jump to search
Line 126: Line 126:
* QObject vs QWidget vs QMainWindow http://stackoverflow.com/questions/3298792/whats-the-difference-between-qmainwindow-and-qwidget-and-qdialog
* 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/
* size().width() can get the width of a widget. See http://www.zetcode.com/gui/qt4/customwidget/
* [http://qt-project.org/doc/qt-4.8/eventsandfilters.html Qt Event System] and [http://qt-project.org/doc/qt-4.8/events.html Event Classes].
* [http://qt-project.org/doc/qt-4.8/eventsandfilters.html Qt Event System] and [http://qt-project.org/doc/qt-4.8/events.html Event Classes].  
* [http://qt-project.org/doc/qt-4.8/qwidget.html#mouseMoveEvent mouseMoveEvent]


= Qt Tricks =
= Qt Tricks =
* [https://github.com/arraytools/Qt/tree/master/example/Qmouseevent Mouse location]
* [https://github.com/arraytools/Qt/tree/master/example/Qmouseevent Mouse location]
* [https://github.com/arraytools/Qt/tree/master/example/ResizeRectangle Resize a rectangle as window]
* [https://github.com/arraytools/Qt/tree/master/example/ResizeRectangle Resize a rectangle as window]

Revision as of 08:10, 30 May 2013

Uses

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

How to Build static Qt on Windows

My experience based on Qt 5.0.2

  • read ReadME file to download perl, python and ruby. Make sure the executable path in in PATH env variable.
  • OpenGL requirement: 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.
  • 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

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

Qt-Apps.org

http://qt-apps.org/ is a good source to find open source projects based on Qt.

Graphics

Scientific

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.

Qt Tricks