4

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
Bilal Yasar
  • 947
  • 2
  • 11
  • 24

2 Answers2

5

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • is there anyway to do this doing `qmake -project` like `qmake -project ADD QT bla bla` . – Bilal Yasar May 17 '14 at 13:07
  • @legelstein: yes, and already mentioned in my reply. You probably have not updated. :) – László Papp May 17 '14 at 13:09
  • thank you for good answer,now i have another problem, when i try to run .exe , it gives Qt5Core.dll error, but when i open this project in qt-creator it doesnt gives any error, why i couldnt run this .exe – Bilal Yasar May 17 '14 at 13:13
1

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

volperossa
  • 1,339
  • 20
  • 33