5

I'm somewhat new to C++ and to Qt 5.2.1. I'm actually learning how to use Qt. To do it as easy as possible, I'm using Qt Creator 3.0.1.

I've written this little piece of code in the main.cpp file of my project :

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QPushButton bouton("Hello !");
    bouton.show();

    return app.exec();

}

And the .pro file (by default) :

SOURCES += \
    main.cpp

I tried to make it run, then I got the issue "QApplication : no such file or directory".

Then, I added "QT += widgets" to the .pro file (full file) :

SOURCES += \
    main.cpp
QT += widgets

And now I get :

Starting <path to .exe>... 
The program has unexpectedly finished.
<path to .exe> crashed

Please, tell me how to make it work. Thanks for reading and for your help.

(OS : Windows 7, Debug : Desktop Qt 5.2.1 MinGW 32bit)

Compile Output :

16:06:54: Running steps for project test...
16:06:54: Configuration unchanged, skipping qmake step.
16:06:54: Starting: "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" 
C:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/PLD/Documents/PLD/Projets Codages/Qt/Qt/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug'
mingw32-make[1]: Nothing to be done for 'first'.
mingw32-make[1]: Leaving directory 'C:/Users/PLD/Documents/PLD/Projets Codages/Qt/Qt/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug'
16:06:55: The process "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" exited normally.
16:06:55: Elapsed time: 00:01.

Application Output :

Starting C:\Users\PLD\Documents\PLD\Projets Codages\Qt\Qt\build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug\debug\test.exe...
The program has unexpectedly finished.
C:\Users\PLD\Documents\PLD\Projets Codages\Qt\Qt\build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug\debug\test.exe crashed
PLD
  • 125
  • 1
  • 4
  • 12
  • Yeah program works fine on working configuration, do Qt examples work for you? Maybe you could also run debug and see what call stack it shows on crash. – Predelnik Feb 08 '14 at 14:32
  • @Predelnik Same issue for the examples : "The program has unexpectedly finished". – PLD Feb 08 '14 at 14:41
  • well I can suggest to try to compile your program in debug and see where exactly it crashes, it at least may give some hints. – Predelnik Feb 08 '14 at 15:01
  • Woah, you better not post it in comments like that but use `pastebin.com` or something like this. And actually your compiling and application logs are not very interesting what I meant is to use some kind of IDE or gdb to see call stack of the place where your program is crashed exactly. – Predelnik Feb 08 '14 at 15:12
  • I edited it in my question to make it readable, sorry :D. – PLD Feb 08 '14 at 15:14
  • Ok, thanks, I'm going to do it. – PLD Feb 08 '14 at 15:16
  • How did you create your project? New Qt Widgets application, Qt Console application..? – otisonoza Feb 08 '14 at 15:21
  • Could you show us the full .pro file please? – otisonoza Feb 08 '14 at 15:23
  • Do you have a moc_mainwindow.cpp ? – dexterous Feb 08 '14 at 15:36
  • @otisonoza I created my project as an empty qt project – PLD Feb 08 '14 at 15:41
  • @otisonoza You can see the full .pro file in my question. – PLD Feb 08 '14 at 15:43
  • @SHREYASJOSHI No, the file I've created are : "test.pro" and "main.cpp". – PLD Feb 08 '14 at 15:44
  • 1
    I would say do the following from scratch - New file or project - choose - QT Widget Application - under Applications. Give a name. Do next and finally the code will be ready. Now, in the main.cpp overwrite with you stuff. it should work if there is no env issue. – dexterous Feb 08 '14 at 15:49
  • @SHREYASJOSHI Same issue by doing what you adviced :(. – PLD Feb 08 '14 at 17:14
  • I get the `make: Nothing to be done for 'first'.` issue when trying to build for Android on Linux. – Geremia Jan 20 '16 at 03:01

2 Answers2

1

The code looks good. One explanation for what you get would be incompatible DLLs (e.g. Debug vs Release builds, or MSVC vs MinGW). You could start depends.exe with your .exe and check whether it picks up libraries from unexpected locations.

Aguest
  • 151
  • 2
  • I had a case where I had some .Qt runtime dll's in the "release" directory. Removing them solved my problem from within QtCreator. Running the program from Windows Explorer produced a runtime error about a missing entry point in a .dll. – CodeLurker Jul 07 '18 at 09:59
-1

I've look all over the web, seeking how to install Qt5. There's not enough tutorials on it and it's very puzzling to make it work properly on Windows.

I have finally installed Qt4, which is more stable and easier to make it work.

PLD
  • 125
  • 1
  • 4
  • 12