Compile Qt creator project in a Linux terminal
-
Hi! All I really want to do is to compile a Qt creator project in a terminal, now I know that if you only have one main.cpp script like this one for example:
#include <QApplication>
#include <QLabel>
#include <QWidget>
int main(int argc, char *argv[ ])
{
QApplication app(argc, argv);
QLabel hello("<center>Hello World</center>");
hello.setWindowTitle("Example program");
hello.resize(400, 400);
hello.show();
return app.exec();
}
you can simple write:
qmake -project
qmake file.pro
maketo compile it. But if you have made a program in Qt creator you will have a lot of more scripts like main.cpp, mainwindow.cpp and mainwindow.h. How would someone go about compiling such a program if you could only use a terminal or console in Linux? (Debian Jessie)
-
@ManlishPotato So
qmake -project
is only run once. It is basically just to create a skeleton .pro file.Once you have that you modify your project file as needed for your build.
In your case it would look something like this:
###################################################################### # Automatically generated by qmake (3.0) Tue Jan 10 17:23:42 2017 ###################################################################### TEMPLATE = app TARGET = tmp INCLUDEPATH += . QT += gui widgets # Input HEADERS += mainwindow.h \ whateverelse.h SOURCES += main.cpp \ mainwindow.cpp \ whateverelse.cpp
You would add your new source/header files in their appropriate spots. Then to build you would just:
qmake && make
Note: If you use the multiline style for
HEADERS
andSOURCES
make sure you put the\
at the end of each line to continue on the next line, otherwise it needs to be all one line likeHEADERS += main.h mainwindow.h etc.h
. -
Thank you! That totally works. I actually noticed now that if you just run qmake -project, it will actually automatically include the scripts.
-
@ManlishPotato It does, but it stomps all your changes to your pro file. You really only want to run it once to create your skeleton then modify it as necessary when your project evolves.
So things like
QT += gui widgets
don't get auto generated.Although they may have changed how it works since last I used it and it may just modify the pro file now without stomping. I use cmake these days. :)