可以使用.cpp
和.h
文件制作项目文件.pro
,这个GitHub演示文件包含CMakeLists.txt,MainWindow.cpp MainWindow.h,MainWindow.uimain.cpp
文件,但是没有.pro
文件如何制作.pro
为了执行此代码,第一步是生成 .pro,因为它打开一个终端并执行:
qmake -project
将生成一个 .pro 文件,其中包含包含该文件的文件夹的名称,并将包含类似于以下内容的内容:
sizegripitem-master.pro
######################################################################
# Automatically generated by qmake (3.1) Tue Oct 24 12:36:31 2017
######################################################################
TEMPLATE = app
TARGET = sizegripitem-master
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
HEADERS += SizeGripItem.h demo/MainWindow.h
FORMS += demo/MainWindow.ui
SOURCES += SizeGripItem.cpp demo/main.cpp demo/MainWindow.cpp
在这些之后,我们必须指出模块,正如我所看到的,类只需要模块核心、gui 和小部件,为此我们添加以下内容:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
您应该做的另一件事是更新一行代码以与Qt5兼容,在文件main中.cpp更改:
#include <QtGui/QApplication>
自:
#include <QApplication>