PDA

View Full Version : C++ GUI Programming



Mike_m
23rd June 2017, 04:14
I am new to Qt programming, with good understanding of C++.
I bought Prentice Hall Book, "C++ GUI Programming with Qt 4, Second Edition" by Blanchette and Summerfield. (2008 Published)
I have downloaded this books source code files from the book publisher's web site.

I have downloaded and installed on Windows, latest trial version of Qt free for about one month.

Following is above book's first program:

// hello.cpp
#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}

Qt is saying No such file or directory for both QApplication and QLabel

Is there a way to fix above program, build and run please?

This book has many excellent Qt programming chapters. I like to be able to load the projects from this book into Qt Creator practice the Qt concepts please
Thanks,
Mike

Santosh Reddy
23rd June 2017, 11:10
How did you install QtCreator, stand alone installer or from the Qt installation, or some other way ?

Mike_m
23rd June 2017, 11:28
Installed using Qt installation. Thanks.

Added after 7 minutes:

I searched for QAapplication file on my Windows computer C drive and found following path for the QApplication include file:
C:\Qt\5.9\mingw53_32\include\QtWidgets

I am trying to add this folder path to the include path in Qt.
How to add (menu, sub-menu selections?) this QtWidgets include path please?

Santosh Reddy
23rd June 2017, 11:46
Can you show the "QT" variable assignments in project file i.e. the .pro file.

Mike_m
23rd June 2017, 11:52
I have hello.pro file and it has only following two lines:
TEMPLATE = app
SOURCES = hello.cpp

Lesiok
23rd June 2017, 12:00
Start new project in Qt Creator with wizard. Then look in the created PRO file.

Mike_m
23rd June 2017, 12:02
I ran qmake command and now I have following lines in hello.pro
TEMPLATE = app
TARGET = hello
INCLUDEPATH += .

Can I manually add my QApplication path to above INCLUDEPATH line?

Santosh Reddy
23rd June 2017, 13:11
No.

Here try this.
https://wiki.qt.io/Basic_Qt_Programming_Tutorial#Baby_steps:_Creating _a_new_project

d_stranz
23rd June 2017, 17:03
I bought Prentice Hall Book, "C++ GUI Programming with Qt 4, Second Edition" by Blanchette and Summerfield. (2008 Published)

Be aware that between Qt4 (for which this book was written) and Qt5 (which you are presumably using), the locations of Qt header files and almost the entire Qt source tree layout changed completely. In addition, there are some argument changes to some very basic classes and methods. So examples from Blanchette and Summerfield's book will probably not immediately compile from the downloaded source. The book is otherwise a great way to learn the basics of the C++ side Qt.

Normally, you do not need to add explicit paths to Qt header files to the .pro file - when you "configure" the project with the correct "kit" in Qt Creator, it will set up the build environment to automatically find what it needs. The INCLUDEPATH directive in the .pro file is usually used for non-Qt headers, like those from external libraries.

Mike_m
24th June 2017, 02:01
Santosh: Thank you very much for the program and information. I will go through your example.

d_stranz:
Thank you very much for the very useful information. We hope the authors & publisher soon updates the book for Qt5 software.

Is there any other good Qt5 book with content/information topics similar to the Blanchette and Summerfield book, please?

d_stranz
24th June 2017, 16:24
Witold Wysota and his colleague Lorenz Haas have written a book "Game Programming using Qt (http://a.co/dgtiHID)" which really isn't much about game programming at all, but is a basic book on Qt5 C++ and QML. It's the first book I know of that treats Qt Quick and QML in any depth (150 pages). It is pretty well written, and I guess the "game programming" aspect of it is that the examples are based on developing game-like programs. There are a couple of other "cookbook" books, but these aren't as helpful for beginners as Wysota and Haas.

I have found the books published through Prentice-Hall and Packt to be generally the best quality in terms of content, style, readability. Summerfield has another Qt4 book, "Advanced Qt Programming" which goes into the Model-View architecture in great depth. M-V hasn't changed much between Qt4 and Qt5, so it is still my go-to book when I have questions.

Mike_m
24th June 2017, 22:57
d_stranz:
Thank you for helpful information about good Qt books.

Weichao
25th June 2017, 11:49
I've encountered exactly the same problem - even QApplication is unknown. I've installed the whole Qt package using the installer I've downloaded from the Qt official site.

Because of this problem I've switched back to an old Qt version: 4.6. The whole package is on a DVD of a Qt 4.6 book I've found in a library. I've borrowed it because it contains a chapter on Qt Creator, and I want to learn to use it, especially use it to debug a program. Now I've made a debug test and it seems to work.

If you are in Germany, you can try to get the book of Jürgen Wolf "Qt 4.6 Gui-Entwicklung mit C++" (ISBN 978-3-8362-1542-8) from Galileo Computing.

Weichao

Radek
25th June 2017, 15:11
TEMPLATE = app
TARGET = hello
QT = core gui widgets


The QApplication and QLabel headers were not found because you haven't specified that your app is a windowed one. The above .pro file is for Qt5. If you are using Qt4 then without "widgets":



TEMPLATE = app
TARGET = hello
QT = core gui

Weichao
25th June 2017, 15:25
Thank you, Radek! I've read somewhere that the CObject::connect() function for signal-slot in Qt5 is different than that in Qt4. Can only the new one be used in Qt5 or both versions will be accepted? I intend to use Qt4 for a while, since all books I have are for this version.

Radek
25th June 2017, 17:20
It is backward compatible, therefore, yes. The Qt5 connect() allows you more kinds of connecting. Al long as you won't need Qt5-specific connecting, you can compile both with Qt4 and Qt5. As to the books: they are well usable both for Qt4 and for Qt5. The Qt5 extensions are rather few and you can learn them from online help - but "learning Qt" is "reading the Qt4 books" still.