6

我想知道如何在 QTCreator 中将 QT 项目用于另一个项目。我用这个层次结构创建了一个子目录测试项目:

MainProject
  MainProject.pro
  ConsoleSubProject
    ConsoleSubProject.pro
    main.cpp
    firstclass.hpp
    firstclass.cpp
  GuiSubProject
    GuiSubProject.pro
    main.cpp
    mainwindow.hpp
    mainwindow.cpp

我想在 GuiSubProject 中使用类“firstclass”(ConsoleSubProject)。为此,我在 GuiSubProject.pro 中添加了这一行:

include(../ConsoleSubProject/ConsoleSubProject.pro)

当我尝试构建项目时,它给了我错误:

MainProject/GuiSubProject/mainwindow.hpp:4: error: QMainWindow: No such file or directory

如果您对如何将项目类用于另一个项目有任何想法?

问候

4

2 回答 2

5

你可以这样做:

MainProject/common.pri

    INCLUDEPATH  += $$PWD/ConsoleSubProject
    SOURCES      += $$PWD/ConsoleSubProject/firstclass.cpp
    HEADERS      += $$PWD/ConsoleSubProject/firstclass.hpp

MainProject/ConsoleSubProject/ConsoleSubProject.pro

    include(../common.pri)
    QT += core
    SOURCES      += main.cpp

MainProject/GuiSubProject/GuiSubProject.pro

    include(../common.pri)
    QT += core gui
    SOURCES      += main.cpp mainwindow.cpp
    HEADERS      += mainwindow.hpp
于 2013-01-30T16:29:00.680 回答
0

而不是你的 GuiSubProject.pro 中的 include(../.....) 它应该是

    INCLUDEPATH    = ../ConsoleSubProject
于 2013-01-30T15:06:48.880 回答