简体   繁体   中英

Running a QT application from Command promt in WIndows

I have made a small QT application and i am trying to run it thru command prompt on Windows:

#include <QMainWindow>
#include <QLabel>

int main(int argc,char* argv[])
{
    QMainWindow a(argc,argv)
    QLabel *NewLabel = new QLabel("Hi i am a label");
    NewLabel->show();
    return a.exec();
}

after doing qmake -project and then qmake -TestPrg.pro then i try make ,here it fails with following error:

D:\TestPrg>make
make -f Makefile.Debug
make[1]: Entering directory `D:/TestPrg'
Makefile.Debug:58: *** missing separator.  Stop.
make[1]: Leaving directory `D:/TestPrg'
make: *** [debug] Error 2

If we look at makefile.debug ,line number 58 and add a TAB before "<<",it complains at someother line number.So i feel there is something wrong in the compiler options ,can someone guide how to make it working.

Thanks alot

I have just made an example work on my machine. The code goes below, but you have at least a few mistakes, namely:

  • You use QMainWindow for being the application as it seems as opposed to QApplication. That is not going to compile.

  • Respectively, you would need to include QApplication rather than QMainWindow.

  • You miss a semi-colon after the first statement in the main function.

  • You construct a QLabel on the heap needlessly. In this particular scenario, it could be a simple stack object.

  • You use invoking qmake as qmake -foo rather than just qmake or make foo .

  • You are trying to use "make" in the Windows Command prompt as opposed to nmake or jom . If you use Visual Studio and MSVC, do not mix it with mingw, cygwin and other things. Just use nmake, otherwise, yes, use make for the latter options.

main.cpp

#include <QApplication>
#include <QLabel>

int main(int argc, char **argv)
{
    QApplication a(argc, argv);
    QLabel NewLabel("Hi i am a label");
    NewLabel.show();
    return a.exec();
}

main.pro

TEMPLATE = app
TARGET = main
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp

Build and Run

* qmake
* nmake
* main.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM