Important: Please read the Qt Code of Conduct -

How can I compiled and run programs?

  • Hey, kids
    I created a new Project, Qt Created this file for me
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow){

    delete ui;

    I then clicked on the green arrow, I ~think the program compiled, then I pressed Ctr-R, but I got the same results. How can I compiled and run this program?

  • Moderators

    Please wrap your code in '@' tags.

    [quote]but I got the same results[/quote]

    What were those results? Any warings, error messages, etc? Also, please add which Qt version, compiler and operating system are you on.

  • Here is a good tutorial on "building and running an example": .You should have a good grasp after you go through it.

  • This is a good link to a "youtube video": that would help

  • Hello

    The green arrow button and Ctrl+R produce the same result: compile and run, whereas the hammer button just compiles. Follow musimbate's posted links to learn more.


  • @
    #include <QCoreApplication>
    #include <iostream>
    #include <QDebug>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);
    qDebug << "Hello world";

    return a.exec&#40;&#41;;

    According to the video tutorial, after clicking on the green arrow I should be able to see a console window, but I don't get anything, absolutely nothing!
    Please note that @#include <iostream>@ is not recognized as a valid header-file and qt underlines it. Needless to say is that none of the std library is recognized.
    I am using VS10 Express edition as well as qt-windows-opensource-5.0.0-msvc2010_32-x86-offline.


  • ah, progress, if we can call it that.
    After trying again, I got this message!

    Starting D:\dev\qt\qtTest1-build-Desktop_Qt_5_0_0_MSVC2010_32bit_SDK-Debug\debug\qtTest1.exe...
    Cannot change to working directory 'D:/dev/qt/qtTest1-build-Desktop_Qt_5_0_0_MSVC2010_32bit_SDK-Debug': The system cannot find the file specified.

    D:\dev\qt\qtTest1-build-Desktop_Qt_5_0_0_MSVC2010_32bit_SDK-Debug\debug\qtTest1.exe exited with code -1

  • Moderators

    Don't know how it works on Windows, but you can turn off checkbox "Run in Terminal" in your project settings, and then QtC will show you result in the application output pane.

    Does that path exist? What happens when you turn shadow building off?

  • I think you should try to install those SDKs that have everything set up for you.It helps you focus on Qt rather than spend time trying to get the set up right.

    If you have a linux platform go to your command line and type the following:
    @sudo apt-get install build-essential qt4-designer qtcreator
    qtcreator-doc qt4-demos qt4-doc qt4-dev-tools libqt4-dev@
    it should set up everything for you.It is not the latest Qt but it works .I am sorry i dont have a quick link to a windows SDK,I ll post it here as soon as i find it.
    Hope this helps.

  • I see, it sounds like Qt does provide cross platform code, but it just does not install well across in all other platforms but Linux, or perhaps the version I am using (Five 0) is not really ready for WinOS.
    Are previous versions of Qt better suited for WinOS?
    Are lower versions still available? and if so, where do I get them?


  • Moderators

    Have tried turning shadow building off?

    Qt 4.7 and Qt 4.8 are still active branches,and will continue to receive bug fixes for some time. You can find them in the same place everything else is - in the Downloads section.

  • The latest version of Qt has installed with no problem on my windows 7.Just go to the "download page ": and chose Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB).I assume you are working on a windows platform since you mentioned MSVC2010.

  • Moderators

    No reason to download MinGW when he already has MSVC installed.

  • Hey sierdzio,what does shadow building exactly do,I would appreciate it if you explained a bit or pointed to a place i could learn about it.

  • Moderators

    Newer builds of Qt Creator (I think it begun with 2.2 or around that release) default to use of shadow building. It basically means that the IDE changes output folders specified by the build system (qmake in most cases) and places the result in another directory, a shadow build directory, usually outside the source directory. A bit annoying to some people like me, but it seems to be a general trend (Xcode, VS are doing the same), and does indeed have advantages to it.

  • Thanks ,i have seen it for some time and never really took time to explore it.I'm glad you mentioned it

  • [quote author="musimbate" date="1360324098"]Hey sierdzio,what does shadow building exactly do,I would appreciate it if you explained a bit or pointed to a place i could learn about it.

    I would like to add few points

    [quote author="Tobias Hunger" date="1358331843"][/quote]

    Shadow-building has lots of advantages, too, so that is why we encourage its use so much: You can switch between different kinds of builds without having to clean/rebuild, you keep your source dir clean, you avoid trouble when working with different configurations, etc. It really is the good-thing(TM).

    [quote author="sierdzio" date="1360324508"] A bit annoying to some people like me, but it seems to be a general trend (Xcode, VS are doing the same)[/quote]

    You can in fact turn off shadow building from the wizard: Just set the build directory to the source directory. In 2.7 there is a way to change the default build directory in Tools>Options>Build & Run>General. Setting it to '.' will effectively turn of shadow building globally.


  • Qt5 comes with its own IDE and RAD, and it works well with MSVC and MinGW. MSVC is very extensive and carries with it a heavy load that is all installed in the HDD. I find MinGW to be better suited for Qt5 for this particular reason.
    But in this world, good things don't come easy, that is why we appreciate them so much. When installing qt-win-opensource-4.8.4-mingw, I get this message:
    Qt OpenSource 4.8.4 Setup
    There is a problem with your MinGW installation:

    g++ not found in C:\MinGW\bin\

    Do you still want to continue? (Your installation may not work)
    Yes No

    which is true, since MinGw was installed in the D:\ drive and not in the C:\ drive. Please note I have added MinGW to the path and 'echo %path%' confirms it, so the path has it, but the Qt installer does not see it.
    How can I solve this problem?
    Reinstalling MinGW in the C:\ drive is a choice, but I would rather any other option.

    Thanks in advance

Log in to reply