qmake does not add widgets

你说的曾经没有我的故事 提交于 2019-12-10 20:17:23

问题


i have a simple program. my program is:

 #include <QApplication>
 #include <QLabel>

 int main(int argc, char *argv[])
{
 int rc ; 
    QApplication app(argc, argv);  
     QLabel *label = new QLabel("Hello Qt!");
    label->show();
     rc = app.exec();
     return(rc) ;
}

i want to compile and build this code in command line. i have installed qt and mingw.

first my command is:

  qmake -project

then i give this command.

  qmake

then qmake creates .pro file which is:

 TEMPLATE = app
 TARGET = HELLO
 INCLUDEPATH += .

 # Input
 SOURCES += hello.cpp

i think this file must inclue ' QT += widgets' but it doesnt. i dont know why. finally, i call mingw make

and it gives error.

when i add .pro file QT += widgets then call mingw-make, it works and creates .exe file.

then my question is that, why qmake automatically add QT += widgets , how can i do this? i dont want to add manually.


回答1:


how can i do this? i dont want to add manually.

You can do the following things:

1) You could use QtCreator and select the widget based application.

2) qmake -project "QT += widgets"

but nothing more. QMake is not a C++ code project parser.

Also, note that you could use greaterThan(QT_MAJOR_VERSION, 4):QT+=widgets to be compatible with Qt 4 if that matters for you since the widgets were in the gui module for Qt 4 and core and gui are added by default. They were put into their own widgets module in Qt 5.




回答2:


if you are a linux user, you could make a little bash script like this

#!/bin/bash
if [ "$1" == "-project" ]; then
 qmake $@ "QT += widgets gui"
else  
 qmake $@
fi

(following the point 2 of lpapp) and place it in /usr/bin directory.. if you want, you could rename qmake to something like qmake_old, rename the script as "qmake" and then

#!/bin/bash
if [ "$1" == "-project" ]; then
 qmake_old $@ "QT += widgets gui"
else
 qmake_old $@
fi

so you can normally call qmake ad it does automatically what you want (NB don't forget chmod +x ) tested on ubuntu 14.04



来源:https://stackoverflow.com/questions/23711592/qmake-does-not-add-widgets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!