Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to use part of one project in other project?
Draqun last edited by
This is my first real app with QT and QtCreator. Can someone tell me how in QtCreator 3.5.1 in Ubuntu use part of one project into another? Directory three looks that
Project/ my-qt-project/ inc/ #some headers src/ #some sources main.cpp my-qt-project-gui/ main.cpp #other sources
my-qt-project is a console version of app. The second one is version with GUI which use a lot of code from the first one, but I cannot import headers and compile it. In project build settings I set my-qt-project as a dependency.
There a simple way to share part of one project with another? I tried use https://wiki.qt.io/SUBDIRS_-_handling_dependencies but it does not work.
http://stackoverflow.com/questions/16876690/qt-creator-how-do-i-add-one-c-project-to-another - I was here too.
Hi and welcome to devnet,
The subdirs template is the right thing to use. Usually you would create one or more library projects with the common code and then one project per application.
What did you try exactly ? Can you share your .pro files ?
Draqun last edited by
CONFIG += c++11 QMAKE_CXXFLAGS += -std=c++11 QT += sql QT -= gui TEMPLATE = app TARGET = qt-simple-notifier INCLUDEPATH += . \ include # Input SOURCES += main.cpp \ src/QtSimpleNotifier/DatabaseManager.cpp DISTFILES += \ LICENSE \ README.md HEADERS += \ inc/QtSimpleNotifier/DatabaseManager.h
Project with GUI
template = subdirs SUBDIRS += ../qt-simple-notifier #include(../qt-simple-notifier/qt-simple-notifier/inc/*) #include(../qt-simple-notifier/qt-simple-notifier/src/*) INCLUDEPATH += ../qt-simple-notifier CONFIG += c++11 QMAKE_CXXFLAGS += -std=c++11 QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = qt-simple-notifier-gui TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ addreminderdialog.cpp HEADERS += mainwindow.h \ addreminderdialog.h FORMS += mainwindow.ui \ addreminderdialog.ui RESOURCES += \ resources.qrc DISTFILES += \ LICENSE \ README.md
My *.pro files.
I don;t want create library project with shared code. I just want include and compile a few class in project with GUI from project with console interface.
Even without a library, your design is wrong.
You should have something like:
With MyProject being the subdirs template pointing to the other two. Then in your GUI project you'll use
SOURCES += ../cli_project/file_you_want.cppetc.
Draqun last edited by Draqun
That was more complicated than I thought.
Thanks for help. Now all work fine.
https://github.com/Draqun/qt-reminder - link to project with valid files.
Why are you adding the src folder to