Hello!
As per title, I'm working on a project, trying to get 2 executable targets (one GUI, the other console) which share some common code. What I have done so far:
Top project file, qspeedtest.pro
TEMPLATE = subdirs
SUBDIRS = cli gui
cli.file = qspeedtestcli.pro
gui.file = qspeedtestgui.pro
OTHER_FILES += resources/config.ini \
README.txt
TEMPLATE = subdirs
SUBDIRS = cli gui
cli.file = qspeedtestcli.pro
gui.file = qspeedtestgui.pro
OTHER_FILES += resources/config.ini \
README.txt
To copy to clipboard, switch view to plain text mode
In the same directory, qspeedtestcli.pro
QT -= gui
TARGET = qspeedtestcli
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
SOURCES += main_qspeedtestcli.cpp \
qspeedtestcli.cpp \
sharedclass.cpp
HEADERS += qspeedtestcli.h \
sharedclass.h
RESOURCES += resources/resources.qrc
QT -= gui
TARGET = qspeedtestcli
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
SOURCES += main_qspeedtestcli.cpp \
qspeedtestcli.cpp \
sharedclass.cpp
HEADERS += qspeedtestcli.h \
sharedclass.h
RESOURCES += resources/resources.qrc
To copy to clipboard, switch view to plain text mode
In the same directory, qspeedtestgui.pro
TARGET = qspeedtest
TEMPLATE = app
SOURCES += main_qspeedtest.cpp \
qspeedtest.cpp \
sharedclass.cpp \
mainwindow.cpp
HEADERS += qspeedtest.h \
sharedclass.h \
mainwindow.h
FORMS += mainwindow.ui
RESOURCES += resources/resources.qrc
TARGET = qspeedtest
TEMPLATE = app
SOURCES += main_qspeedtest.cpp \
qspeedtest.cpp \
sharedclass.cpp \
mainwindow.cpp
HEADERS += qspeedtest.h \
sharedclass.h \
mainwindow.h
FORMS += mainwindow.ui
RESOURCES += resources/resources.qrc
To copy to clipboard, switch view to plain text mode
The above is a (somewhat) minimal example of the actual contents of my project files. As you can see, there is some common code that the 2 subprojects share, represented here by the class files sharedclass.h and sharedclass.cpp. In the actual code, there are more classes being utilized in both executables. For the convenience of anyone wishing to examine the rest of the files, here is a ZIP archive containing the above project with some skeleton code. It is perfectly compilable:
qspeedtest.zip
The above layout works but
1. It gives a horridly redundant view of the file hierarchy inside Qt Creator:
qtcreator04.jpg
2. It just doesn't feel right!
So my question is: Is there a better and/or more proper way to design and organize this project's code? I was thinking that maybe creating a shared dynamic library that holds the common code would be a nice approach, but I have yet to locate a thorough "From A-Z" example demonstrating this approach. And my own attempts with the help of only the Qt documentation proved inadequate.
Any thoughts or advice? Thanks in advance!
Bookmarks