我制作了一个小型 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();
}
在完成 qmake -project
之后
然后 qmake -TestPrg.pro
然后我尝试 make
,这里失败并出现以下错误:
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
如果我们查看 makefile.debug
,第 58 行并在“<<”之前添加一个制表符,它会提示其他行号。所以我觉得编译器选项有问题,有人可以指导如何使其工作。
非常感谢
最佳答案
我刚刚在我的机器上做了一个例子。代码在下面,但你至少有一些错误,即:
您使用 QMainWindow 作为应用程序,因为它看起来与 QApplication 相反。那不会编译。
相应地,您需要包含 QApplication 而不是 QMainWindow。
在 main 函数的第一个语句之后漏掉了一个分号。
您不必要地在堆上构造了一个
QLabel
。在这个特定场景中,它可以是一个简单的堆栈对象。您使用
qmake -foo
调用 qmake 而不仅仅是qmake
或make foo
。您正在尝试在 Windows 命令提示符中使用“make”而不是
nmake
或jom
。如果你用Visual Studio和MSVC,不要和mingw、cygwin之类的混用。只需使用 nmake,否则,是的,为后面的选项使用 make。
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();
}
主程序
TEMPLATE = app
TARGET = main
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
构建并运行
* qmake
* nmake
* main.exe
关于c++ - 在 WIndows 中从命令提示符运行 QT 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21041690/