Qt: Difference between revisions
Line 618: | Line 618: | ||
this, SLOT(on_lineEdit_textChanged())); | this, SLOT(on_lineEdit_textChanged())); | ||
</pre> | </pre> | ||
However, just like the GUI created in VBA, the text in the QLabel can be cut. So it is best not to use Qt Designer from my opinion. |
Revision as of 18:07, 9 March 2014
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 Calibre, 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)
- APK Icon Editor Edit and replace APK icons, easily and quickly. Written in C++ / Qt. Open source. See also howtogeek.com page.
- ggobi
- Juk Application in KDE.
- Yarock music player.
Binding with different languages
http://qt-project.org/wiki/Category:LanguageBindings
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/
precompiled Qt 4.8.5 MinGW binary
Got an error of 'Only versions with W32API 3.13 are supported'. See https://bugreports.qt-project.org/browse/QTBUG-26137. I am using MinGW-get-setup.exe to install MinGW. The gcc version is 4.7.2-1.
Some suggestions are to install old versions of GCC. http://qt-project.org/forums/viewthread/22352 and http://qt-project.org/wiki/MinGW.
Download gcc 4.4.0 (mingw-gcc440_1.zip) from search google. Just unzip it to C:\. There is no need to put 'C:\mingw\bin' in Windows environment variable PATH. At the end, we will have a new folder C:\mingw.
Although Qt can be installed without any errors, when I try some examples, some of them will give an error "The program has unexpectedly finished". Update: the error was caused by previous build residue. Just delete the build directory (Debug/Release) and re-build again. Things works well. However, remember the executable file can only be run through Qt Creator. It does not work by just double clicking the executable file.
The order of installation is
- mingw
- Qt library
- Qt creator
precompiled Qt 5.1.1 MSVC
I try Qt 5.1.1 for Windows 32bit (VS 2010, OpenGL 504 MB) on my Windows 7 + VS 2010. The <fancybrowser> works fine.
Note that after I install it to "C:\Qt\5.1.1" directory, I will get the following sub-directories "5.1.1" (another one), "Licenses", "Tools", "vcredist" with a few files. The <Qt Creator> cannot be unselect in installation and it is located under "Tools" folder.
Transition of Qt 4.x to 5
http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5
In summary, we need to add the following line to .pro file
QT += widgets
How to Build static Qt on Windows
General resource:
- 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
Why do we need to
Using the VS2010 version of Qt to build an app has a problem when it is time to distribute the application. In my first example of GUI with button & label, I need to put the following 7 dll files in the same exe directory in order to run the exe file from Windows Command Prompt instead of Qt Creator.
- 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
My experience based on Qt 4.x.x
MSVC 2010
- 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 replace
QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi QMAKE_CFLAGS_DEBUG = -Zi -MDd
with
QMAKE_CFLAGS_RELEASE = -O2 -MT QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi QMAKE_CFLAGS_DEBUG = -Zi -MTd
according to the page
- Change PATH variable and add C:\Qt\4.8.4\bin.
- Open Visual Studio command prompt (see the Configure Options for Qt in Manual for the options) and
cd C:\Qt\4.8.4 set PATH=C:\QT\4.8.4\bin;%PATH% configure -platform win32-msvc2010 -static -opensource -debug-and-release nmake sub-src
If we need to reconfigure, run make confclean and configure. Some guide also includes '-release' option.
See here when we want to build both release and debug mode applications. If we just specify '-release' in the configure line, we will not be able to create debug program although I still do not know how to use debug program in Qt creator with MSVC.
For mingw, we need to use 'mingw32-make' instead of 'make' or 'nmake'. See Building Qt Desktop for Windows with MinGW.
MinGW
Download and install MinGW-gcc440_1 & ActivePerl.
C:\Perl64\site\bin, C:\Perl64\bin (these 2 were added by ActivePerl installer by default), C:\mingw\bin and C:\Qt\4.8.5-src should be put in the PATH variable.
I have successfully built Qt using MinGW.
configure mingw32-make
When I try to run my program (either Debug or Release version), I get an error The program can't start because QtCore4.dll is missing from your computer. Try reinstalling the program to fix this problem.. Reboot?
For Qheatmap application, we still need to copy 2 dll files: mingwm10.dll(11 KB) and libgcc_s_dw2-1.dll(43 KB) from C:\mingw\bin folder to the same folder as Qheatmap.exe. These 2 files were also mentioned in Building Qt Desktop for Windows with MinGW.
My experience based on Qt 5.x.x
- See the instruction on Git
- The directory structure in Qt 5 is quite different from Qt 4. For example, \bin directory is now under \qtbase directory not under the root directory.
- 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.1.1\qtbase\mkspecs\win32-msvc2010
- run the following
cd c:\qt\5.1.1-src set PATH=C:\QT\5.1.1-src\qtbase\bin;C:\qt\5.1.1-src\gnuwin32\bin;%PATH% set QMAKESPEC=win32-msvc2010 configure -debug-and-release -static -opensource -opengl desktop -nomake examples -nomake tests jom
It works when I tested qtbase\examples\widgets\painting.
Build Webkit
- http://trac.webkit.org/wiki/BuildingQtOnWindows
- http://qt-project.org/wiki/MinGW-64-bit
- http://qt-project.org/forums/viewthread/20484
- I add 'C:\win_flex_bison;C:\GnuWin32\bin' to PATH variable for Webkit build in my Windows 7. The 'C:\win_flex_bison' seems not necessary since Qt\5.1.1-src\gnuwin32\bin has included win_flex.exe.
- Still I got an error that 'Building WebKit with Qt versions older than 5.0 is not supported.'
Try on Qt 5.1.1
- download icu from http://site.icu-project.org/download/51#TOC-ICU4C-Download (64bit MSVC 2010). I unzip and put it under C:\icu folder. This folder contains 3 subfolders: bin64, include and lib64.
- Building Qt Webkit from qt-project.org. Also paying attention to the section of 'ICU on Windows'.
set PATH=%PATH%;C:\icu\bin64 set INCLUDE=%INCLUDE%;C:\icu\include set LIB=%LIB%;C:\icu\lib64 perl qtwebkit\Tools\Scripts\build-webkit --qt --release --minimal
- https://bugreports.qt-project.org/browse/QTBUG-32496
- Got an error
The WebKit build was disabled for the following reasons: * ICU is required. To build QtWebKit with Qt 5 you need to build Qt 5 with l ibICU support. Check for ICU support being mentioned in qtbase/config.summary.
- The static build of WebKit is not successful when I use qt source code. I get the message "Project ERROR: WebKit requires SQLite. Either make it available via pkg-config, set $SQLITE3SRCDIR or build Webkit under qt5.git."
# Open Qt command prompt from Windows Start cd c:\qt\5.1.1\5.1.1\Src\qtwebkit\ perl Tools\Scripts\build-webkit --qt --release --minimal
- The static build of WebKit is not successful when I use SVN version. I get the message "Failed to set up build environment using SQLite. Either make it available via pkg-config, set $SQLITE3SRCDIR or build WebKit under qt5.git."
- Another try according to stackoverflow. First of all, we still need to follow the build instruction for QtWebKit build on Windows to install GNU tools and setup PATH. Open a QT command prompt (The Qt was not from source code but from MSVC binary) and
cd C:\qt\5.1.1\5.1.1\src\qtwebkit qmake
Open another VS 2010 command prompt and
set PATH=%PATH%;C:\icu\bin64 set INCLUDE=%INCLUDE%;C:\icu\include set LIB=%LIB%;C:\icu\lib64 SET SQLITE3SRCDIR=C:\qt\5.1.1\5.1.1\src\qtbase\src\3rdparty\sqlite cd C:\qt\5.1.1\5.1.1\src\qtwebkit nmake
Still get errors "LNK2001: unresolved external symbol _u_charType_51 JavaScriptCore.lib(Lexer.obj)" as reported by this case. This is a good reference.
Install Qt on Ubuntu
It is also necessary to follow http://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.x.x
It is straight forward if we use the binary version installer instead of building from Qt source. Just use 'chmod +x' to make the downloaded file executable and then run the executable file.
./qt-linux-opensource-5.1.1-x86_64-offline.run
It is still necessary to install opengl library by executing sudo apt-get install mesa-common-dev and sudo apt-get install libgl1-mesa-dev.
At the end, the qmake program is available under ~/Qt5.1.1/5.1.1/gcc_64/bin/qmake.
The Qt creator is bundled in the installer so we don't have to download it separately.
Q: How to resolve the error <QPrinter> no such file or directory in Qt 5? Ans: Add QT += printsupport according to http://qt-project.org/forums/viewthread/24668.
Q: How to resolve the error /home/brb/Qt5.1.1/5.1.1/gcc/include/QtCore/qobject.h:214: Error no type named 'Object' in 'struct QtPrivate::FunctionPointer<const char*>'
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. First we download Linux/X11 one from qt-project.org (230MB). It is the same as the source code file. The INSTALL file points to http://qt-project.org/doc/qt-4.8/install-x11.html. We also need to do 'apt-get install libxext-dev' to resolve an error that 'basic XLib functionality test failed'.
tar xzvf qt-everywhere-opensource-src-4.8.5.tar.gz ./configure -static make sudo make install
Note that the last step make install is required; if this is skipped, Qt Creator won't let you to add 4.8.5 as a Kit.
At the end of "./configure", it shows
Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into /usr/local/Trolltech/Qt-4.8.5 To reconfigure, run 'make confclean' and 'configure'.
In .profile (if your shell is bash, ksh, zsh or sh), add the following lines:
PATH=/usr/local/Trolltech/Qt-4.8.5/bin:$PATH export PATH
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.
- here teaches us how to set warning level when compiling a Qt project. Qt project uses the settting in makefile. We can overwrite it by setting something in .pro file
win32:QMAKE_CXX_FLAGS_WARN_ON += -Wextra
Google: Qt change warning level.
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
Qt forum
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)
- Veusz which depends python2, PyQt (Qt4, SIP) and numpy.
- arrowmatcher (not English)
- QtiPlot (require Python)
- MIFit (require Python)
- Tulip (no .pro file, use 'make')
Qt Widget
Qt games
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
Q_OBJECT
This macro is required if a class contains SIGNAL/SLOT.
tr()
tr() means translation; the characters were auto translated depending on system's locale. See http://qt-project.org/doc/qt-4.8/linguist-hellotr.html
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.
From C++ to Qt
See Chap 1 of Foundation of Qt Development book.
No Qt | Qt | |
---|---|---|
Class | List 1.1
#include <string> using std::string; class MyClass { public: MyClass (const string & text); const string& text() const; void setText (const string& text); int getLengthOfText() const; private: string m_text } |
List 1.2
#include <QObject> #include <string> using std::string; class MyClass : public QObject { public: MyClass (const string& text, QObject *parent = 0); ... } |
Main | List 1.3
#include <iostream> int main(int argc, char **argv) { MyClass *a, *b, *c; a = new MyClass ("foo"); b = new MyClass("ba-a-ar"); c = new MyClass("baz"); std::cout << a->text() << "(" << a->getLengthOfText() << ")" << std::endl; a->setText( b-> text() ); std::cout << a->text() << "(" << a->getLengthOfText() << ")" << std::endl; int result = a->getLengthOfText() - c ->getLengthOfText(); delete a; delete b; delete c; return result; } |
List 1.4
#include <QtDebug> int main (int argc, char **argv) { QObject parent; MyClass *a, *b, *c; a = new MyClass ("foo", &parent); b = new MyClass("ba-a-ar", &parent); c = new MyClass ("baz", &parent); qDebug() << QString::fromStdString(a->text()) << "(" << a->getLengthOfText() << ")"; a -> setText( b-> text()); qDebug() << QString::fromStdString(a->text()) << "(" << a->getLengthOfText() << ")"; return a->getLengthOfText() - c->getLengthOfText(); } |
Naming Convention
- Class name starts with an uppercase letter and the words are divided using Camel-Casing.
- The names of the methods all start with a lowercase letter, and the words are again divided by using CamelCasing.
Memory Management
- Chapter 1 of Foundation of Qt Development
- http://www.qtcentre.org/threads/41449-Parent-child-relationship-in-Qt
Parent is on heap. So it has to be deleted manually.
#include <QtGui> #include "addressbook.h" //...every needed header int main(...) { //QApplication app .... QWidget *parent = new QWidget; //a parent for your addressbook AddressBook *myAddressBook = new AddressBook(parent); //pass a pointer to parent widget when you construct an AddressBook object //... other code, maybe some layout if necessary... parent->show(); //will show the chidren widgets too int returnValue = app.exec(); delete parent; //this will delete the parent children too return returnValue; }
OR creating parent on the stack
int main(...) { //QApplication app .... QWidget parent; //a parent for your addressbook - parent is created on stack AddressBook *myAddressBook = new AddressBook(&parent); //pass a pointer to parent widget when you construct an AddressBook object //... other code, maybe some layout if necessary... parent.show(); //will show the chidren widgets too return app.exec(); }
Misc
- If we want to create a new class member to be used in class method, we should declare it in the header file. For example, look at the variable 'label' below. Of course, variables only used locally have not this rule.
class MyButton : public QWidget { Q_OBJECT public: MyButton(QWidget *parent = 0); QLabel *label; private slots: void showText(); }; MyButton::MyButton(QWidget *parent) : QWidget(parent) { label = new QLabel(); // NOT QLabel *label = new QLabel(); } void MyButton::showText() { label->setText("My Text!"); }
- 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.
- Right click context menu
- Can I use Qpainter outside paintEvent or here
- Add background to QWidget
Qt Quick
- Tutorial from qt-project.org.
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 Windows initial posiiton
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.
Get the current working path
Use QCoreApplication::applicationDirPath() to get the current working path or QFile::absolutePath() to get the absolute path from relative one.
Pop up a help file
- QMessageBox: no maximize button on top-right corner. Cannot resize (old Qheatmap)
- QTextBrowser: the html file cannot be part of C++ (Qtextbrowser)
- QLabel: No scroll bar (Qt07_BasicApplication)
- QTextEdit: Good (used in Qheatmap)
- QWebkit
- QTextDocument: no scroll bar (Qt79_drawText)
Convert QString to std::string
http://stackoverflow.com/questions/4214369/how-to-convert-qstring-to-stdstring
.toStdString()
Custom Plots
- Boxplot, line plot, barplot, etc : http://www.qcustomplot.com/
- Histogram: https://www.assembla.com/code/histogram/subversion/nodes
Use boost libraries with an example
http://stackoverflow.com/questions/16998326/using-boost-libraries-in-qt
On Windows OS, we can add the following to the .pro file
INCLUDEPATH += C:/boost/boost_1_53_0/ LIBS += "-LC:/boost/boost_1_53_0/stage/lib/"
On Ubuntu OS, I can use (the first line Qt += widgets is only necessary on Qt 5)
QT += widgets INCLUDEPATH += /home/brb/Downloads/boost_1_55_0/ LIBS += "-L/home/brb/Downloads/boost_1_55_0/stage/lib/"
The following is an example to compute the 95% percentile from the T distribution (df=195) is
#include <QApplication> #include <QLabel> #include <boost/math/distributions/students_t.hpp> using namespace std; using boost::math::students_t; int main(int argc, char *argv[]) { QApplication a(argc, argv); int df = 195; double alpha = .1; students_t dist(df); double T = quantile(complement(dist, alpha / 2)); QLabel *label = new QLabel("T(.95, df=195)=" + QString::number(T)); label->show(); return a.exec(); }
Home directory
QDir::homePath()
Qt Designer
From C++ GUI Programming with Qt book Chapter 2:
In the constructor, we call setupUi() to initialize the form. Thanks to multiple inheritance, we can access Ui::GoToCellDialog's members directly. After creating the user interface, setupUi() will also automatically connect any slots that follow the naming convention on_objectName_signalName() to the corresponding objectName's signalName() signal. In our example, this means that setupUi() will establish the following signal–slot connection:
connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(on_lineEdit_textChanged()));
However, just like the GUI created in VBA, the text in the QLabel can be cut. So it is best not to use Qt Designer from my opinion.