Problem with creating first project and the book “C++-gui-programming-with-qt-4-2ndedition”

Hi all,

I installed “qt-opensource-windows-x86-mingw482_opengl-5.3.0” on my Windows 7 machine. For learning Qt I chose that book (on the title) and started with it.
In getting started, page 10 of that book, the below code is written:

1
2
3
4
5
6
7
8
9
10
#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();
}


But I don’t know how to make that window for writing codes. How to make that project, that is, from what menus, step-by-step.
I also read the Appendixes A & B of the book but those just confuse me more.
I am not sure if i understand exactly what your problem is. Is it running the code above? or is it going to the code editor?
I started with that book but couldn't to write that snip code which is written in page 10 of the book. After quite a while googling the web for the best book on Qt for strat with I found that book. Also Stroustrup suggested that for starting Qt but this book doesn't guide the reader as a beginner.
For example it doesn't say how to make a project and then write that small code for start Qt. I'm so confused.
That book skips over the .pro file for some reason. To see more about that take a look at this.
http://qt-project.org/wiki/Qt_for_beginners_Hello_World

I do not know how much that will help because I just tried it and could not get it to work for some reason(probably something simple I overlooked). Anyway that is kind of old and the newer page shows a better way to start anyway.
http://qt-project.org/doc/qt-5/gettingstartedqt.html

There are several tutorials built into Creator along with the docs. I would also suggest watching a couple of these videos until you get an understanding of how a project is set up.
https://www.youtube.com/watch?v=6KtOzh0StTc&list=PL2D1942A4688E9D63
The instructions on page 11 seem clear to me:
. . . From now on, we will assume that you have a correctly installed copy of Qt 4 and that Qt's bin
directory is in your PATH environment variable. (On Windows, this is done automatically by the Qt installation program.) You will also need the program's code in a file called hello.cpp in a directory called hello. You can type in hello.cpp yourself or copy it from the examples that accompany this book, where it is available as examples/chap01/hello/hello.cpp. (All the examples are available from the book's web site, http://www.informit.com/title/0132354160.) Figure 1.1. From a command prompt, change the directory to hello, and type qmake -project to create a platform-independent project file (hello.pro), and then type qmake hello.pro to create a platform-specific makefile from the project file. (The qmaketool is covered in more detail in Appendix B.) Type make to build the program. Run it by typing hello on Windows, . . .

What are you having problems with?
@norm b:
The problem is on page 10. The authors don't say how to create a project and where into that project put that code!
Thank you admkrk.
@ norm b
Thanks for pointing that out, I did not realize it was talking about using command line. The book also talks about using Designer and it makes me wonder if Creator did not exist, or at least was not included, when it was written. For me make is not recognized on Windows, no problems on Linux, but using Creator is much quicker and easier for anything other than simple widgets anyway.
@admkrk
You're right. That edition of the book was published 2/04/2008 and Qt Creator v1.0 was released 3/03/2009: http://www.osnews.com/story/21072/Qt_4_5_Qt_Creator_IDE_v1_0_New_Qt_SDK_Released

admkrk wrote:
For me make is not recognized on Windows
I don't use Windows at all, but can you not install MSYS? http://www.mingw.org/wiki/MSYS

@khoshtip
It is always good to learn how to do things from the command line, but if you are using Qt Creator:
New Project->Choose(use defaults - Application & Qt Widgets Application )->Next->Next->Next->Finish
Paste your code into main.cpp overwriting the template
Build->Run

To remove mainwindow.h and mainwindow.cpp (not neccessary to run the app):
Right click on the file in the upper left pane->Remove File->OK
Repeat
qmake worked so I figured make would also and I had to use the Qt terminal to get that far. My paths are not all set up right because I do not use a normal file structure. I either need two terminals or have to switch directories back and forth for Java if I use command line. I'm used to things not always working as they are supposed to and that's one of the reasons I set up a couple Virtual Boxes.
@norm b:
Thank you so much for your instructions. They are correct and worked as I expected.

@admkrk:
In start menu of Windows 7 (on my machine) there is a folder named Qt 5.3.0 and when I open/extend it, there isn't any command prompt link. Apparently in this Creator there isn't such a link!
It is buried inside a couple folders. Try Qt 5.3.0 > 5.3.0 > MinGW**.
Topic archived. No new replies allowed.