Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Compile Qt creator project in a Linux terminal

Compile Qt creator project in a Linux terminal

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    ManlishPotato
    wrote on last edited by
    #1

    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
    make

    to 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)

    A 1 Reply Last reply
    0
    • M ManlishPotato

      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
      make

      to 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)

      A Offline
      A Offline
      ambershark
      wrote on last edited by ambershark
      #2

      @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 and SOURCES 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 like HEADERS += main.h mainwindow.h etc.h.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      3
      • M Offline
        M Offline
        ManlishPotato
        wrote on last edited by
        #3

        Thank you! That totally works. I actually noticed now that if you just run qmake -project, it will actually automatically include the scripts.

        A 1 Reply Last reply
        0
        • M ManlishPotato

          Thank you! That totally works. I actually noticed now that if you just run qmake -project, it will actually automatically include the scripts.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @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. :)

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved