$ mkdir quit $ cd quit $ vi quit.cpp
#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton *button = new QPushButton("Quit"); QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit())); button->show(); return app.exec(); }
$ qmake -project $ vi quit.pro
quit.proの最後に「QT += widgets」を追加する。
###################################################################### # Automatically generated by qmake (3.1) Mon May 13 16:36:00 2019 ###################################################################### TEMPLATE = app TARGET = quit INCLUDEPATH += . # The following define makes your compiler warn you if you use any # feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6. 0.0 # Input SOURCES += quit.cpp QT += widgets
$ qmake quit.pro Info: creating stash file /home/nakada/Qt4/quit/.qmake.stash $ ls ./ ../ .qmake.stash Makefile quit.cpp quit.pro $ make g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o quit.o quit.cpp g++ -Wl,-O1 -o quit quit.o -lQt5Widgets -lQt5Gui -lQt5Core /usr/lib/x86_64-linux-gnu/libGL.so -lpthread $ ls ./ ../ .qmake.stash Makefile quit* quit.cpp quit.o quit.pro $ ./quit
Quitボタンをクリックすると終了する。