Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在WIndows中从命令promt运行QT应用程序_C++_Qt_Makefile_Qtgui_Qmainwindow - Fatal编程技术网

C++ 在WIndows中从命令promt运行QT应用程序

C++ 在WIndows中从命令promt运行QT应用程序,c++,qt,makefile,qtgui,qmainwindow,C++,Qt,Makefile,Qtgui,Qmainwindow,我制作了一个小的QT应用程序,并试图通过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.ex

我制作了一个小的QT应用程序,并试图通过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();
}

如果我们查看
makefile.debug
,第58行,并在“之前添加一个选项卡,我刚刚在我的机器上做了一个示例。代码如下,但您至少有几个错误,即:

  • 您使用QMainWindow作为应用程序,因为它似乎与QApplication相反。这不会编译

  • 分别地,您需要包括QApplication而不是QMainWindow

  • 在main函数中的第一条语句后缺少分号

  • 不需要在堆上构造一个
    QLabel
    。在这个特定场景中,它可以是一个简单的堆栈对象

  • 将qmake作为
    qmake-foo
    调用,而不仅仅是
    qmake
    makefoo

  • 您正试图在Windows命令提示符中使用“make”,而不是
    nmake
    jom
    。如果您使用Visual Studio和MSVC,请不要将其与mingw、cygwin和其他内容混合使用。只需使用nmake,否则,可以使用make作为后一个选项

main.cpp 构建并运行
更可能是Makefile中存在多个错误。您可以使用Makefile.debug进行更新吗?以及它引发的第二个错误是什么?
qmake-TestPrg.pro
是错误的。只需使用
qmake
qmake-TestPrg.pro
。QMainWindow a(argc,argv)->将其更改为QApplication a(argc,argv)@Laslo打字错误我只使用了qmake TestPrg.pro。########隐式规则。后缀:.c.cpp.cc.cxx{.}.cpp{debug\.obj:$(cxx)-c$(cxflags)$(INCPATH)-Fodebug\@感谢您的反馈,但下面是在我的命令提示符下使用的内容:D:\TestPrg>qmake-project D:\TestPrg>qmake-D:\TestPrg>qmake-D:\TestPrg.pro D:\make-debug[make]:进入目录
D:/TestPrg'Makefile.Debug:58:**缺少分隔符。停止。生成[1]:离开目录
D:/TestPrg'make:**[Debug]错误2@user3156680:请在干净的环境下重试。另外,您没有注意我写的“nmake”说明。我不能使用“nmake”“,'nmake'不能识别为内部或外部命令、可操作程序或批处理文件。@user3156680:您尚未设置路径。您可以运行visualstudio提示符来解决这个问题,但实际上:您使用的是MSVC还是mingw?您还没有说清楚…我正在使用MSVC,在环境变量中,我将QMAKESPEC设置为“win 32 MSVC.net”。不幸的是,如果我尝试使用VS2010命令提示符而不是打开命令提示符窗口,它将打开此文件夹位置“C:\Windows\System32”,我不知道为什么
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
#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();
}
TEMPLATE = app
TARGET = main
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
* qmake
* nmake
* main.exe