简体   繁体   中英

Using qmake as qmake -project

I want to make a GUI application using Qt and am not able to get started. I wrote the following code in my editor:

#include <QApplication>
#include <QWidget>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QWidget window;
    window.resize(250,150);
    window.setWindowTitle("Simple example");
    window.show();
    return app.exec();
}

Then I make a project.pro file in my current directory with the following content:

SOURCES = qt.cpp
HEADERS = QApplication QWidget
CONFIG += qt warn_on release

Then I type in terminal, qmake -project but the terminal does nothing. Even the command prompt doesn't appear. It just sits idle as if waiting for something, like the following:

user@user:~$ qmake -project
_

How do I make it work?

The following line creates a project source file for you.

> qmake -project

The only thing in this case you need is .cpp & .h files for your project.

Now, remove your project source file you've created. In the directory, you need only .cpp & .h for your project (in your case there is only qt.cpp). Now, go to the terminal and type

> qmake -project -o myproject.pro

This line created a project source file for you and its name is "myproject".

Type (assuming there is only one project source file)

> qmake

The above line created the Makefile.

Now, type

> make

The output (by default in mac) has the extension .app and its name is myproject.app. Now to run it (in mac).

> open myproject.app

As you see, you don't have full control over your project. To overcome this problem, you need to create your own project source file ( which I prefer that).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM