c++ - 我可以使用 .cpp 和 .h 文件制作 .pro 文件吗

标签 c++ qt qt5 qmake

我可以使用.cpp.h 文件制作项目文件.pro吗,这GitHub demo文件包含 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>

关于c++ - 我可以使用 .cpp 和 .h 文件制作 .pro 文件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46916327/

相关文章:

c++ - 删除 QString 中所有出现的特殊字符

c++ - 编码(marshal)或不编码(marshal)

C++ 通用树按两个标准进行比较

c++ - 重载运算符函数失败

qt - 如何将多个外部库添加到 Qt creator .pro (ubuntu)

c++ - Q_IMPORT_PLUGIN,我可以使用多少次?

c++ - Makefile 模式规则无法匹配

c++ - VS2013 与 QT5.3.2 使用 Websocket 并遇到 Unresolved external symbol 问题

c++ - Qt 5.6 - 如何将 QTreeWidget 链接到主窗口?

qt - QML 获取默认字体高度值(以像素为单位)