我可以使用.cpp和.h文件制作.pro文件吗?

Can I make .pro file using .cpp and .h files

本文关键字:文件 pro 可以使 cpp 我可以      更新时间:2023-10-16

可以使用.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>