Bilal Yasar
Bilal Yasar

Reputation: 967

qmake does not add widgets

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.

Upvotes: 4

Views: 3012

Answers (2)

volperossa
volperossa

Reputation: 1431

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

Upvotes: 1

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53173

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.

Upvotes: 5

Related Questions