I have a QML plugin project and my application project plus subdirs project organized like that:
project.pro
plugin/
plugin.pro
Plugin.cpp
Plugin.h
qmldir
app/
app.pro
main.cpp
main.qml
qml.qrc
project.pro:
TEMPLATE = subdirs
SUBDIRS = app plugin
app.depends = plugin
plugin.pro:
TEMPLATE = lib
QT += qml quick
CONFIG += plugin c++11
TARGET = $$qtLibraryTarget(plugin)
PLUGIN_URI = com.test.plugin
SOURCES += Plugin.cpp
HEADERS += Plugin.h
app.pro:
QT += qml quick
SOURCES += main.cpp
RESOURCES += qml.qrc
It builds as expected and now I need to pass path to compiled libplugin.dylib/.so/.dll and qmldir to my application. I see two ways:
Copy plugin files into /path/to/qt/5.10.1/clang_64/qml/com/test/plugin/ using INSTALL qmake variable.
Copy plugin files near the application executable and add this path as relative to the executable using QQmlEngine::addImportPath().
What approach will be better? How to do it?
so i m trying to setup a movable folder for a Qt project where I 'll have this structure and everything will be dependent ONLY with that content..
project\
script.dat "script to invoke qmake with just a click"
qmake.exe
moc.exe
mkspec\ "win32-msvc2010" copy
common\ "necessary by qmake" copy
project.pro
sources\
main.cpp
etc...
headers\
etc...
depedencies\
Qt\
include\
lib\
dll\
e.g.Boost\
include\
lib\
dll\
as can be seen i want a decent folder structure where the script will append the path to the dlls and set QMAKESPEC etc with respect to the %cd% (PWD) directory of the .pro file...
However the problem arises when i invoke qmake.exe
C:\Users\ardit\Desktop\test>qmake -v
QMake version 3.0
Using Qt version 5.2.1 in C:\build-essential\Qt\5.2.1\msvc2010_opengl\lib
and after that
qmake -tp vc
creates a project that has everything linked to my Qt installation and NOT the folder specified in the pro
visual studio additional include directories:
"include";".";"........\build-essential\Qt\5.2.1\msvc2010_opengl\include";"........\build-essential\Qt\5.2.1\msvc2010_opengl\include\QtGui";"........\build-essential\Qt\5.2.1\msvc2010_opengl\include\QtCore";"debug";........\build-essential\Qt\5.2.1\msvc2010_opengl\mkspecs\win32-msvc2010;%(AdditionalIncludeDirectories)
I havent put the Qt installation in the Path, but still the qmake.exe knows it somewhow (registry perhaps?)...
example .pro file where include\ has copy of Qt5\include\ , lib\ and dll\ as well
TARGET= test
SOURCES += main.cpp\
mainwindow.cpp \
glwindow.cpp
HEADERS += mainwindow.h \
glwindow.h
INCLUDEPATH=$${PWD}\include $$PWD
DEPENDPATH=$${PWD}\include $$PWD
LIBPATH=$${PWD}\lib
LIBS+=-L$$LIBPATH -lQt5Core -lQt5Gui -lQt5Widgets
Sidenote: I m new here so plz dont bash me...
any help appreciated...
I have a project in Qt Creator which has several shared library projects and the main project which also contains the main function. What I want is to add a new project which shouldn't be a shared library but just a project with some header files where I keep definitions and error codes. What I wish is to be able to add the path of this project to other projects INCLUDEPATH in order to use those files in other projects.
To do so I created an empty project which .pro file looks like this:
HEADERS += \
myHeader.h
but when I build the whole project it complains that it doesn't find the main in this project with only one header.
Is it possible in QtCreator to achieve this?
Create a .pri file which has your INCLUDEPATH, etc; and then refer to it in your other projects' .pro files:
# Common.pri
INCLUDEPATH += ../myPath
INCLUDE += myHeader.h
# OtherProject.pro
!include( ./Common.pri ) {
error( Could not find the Common.pri file. )
}
INCLUDEPATH += ../myOtherPath
Remember to use the += operator in your .pro files otherwise they will overwrite the .pri file variables.
I have a project that links to a number of shared libraries.
Lets say project A depends on projects B and C
Ideally, I want to impose the following dependencies in my project file:
Rebuild project A if either B or C has been rebuilt since last time project A was built
Use the output for the relevant configuration (i.e. if building project A in debug mode, then use the debug versions of the libs for project B and C)
Does anyone know how I may explicitly express such dependencies in my project file?
After quite a bit of frustration with qmake, I have found what I think is the answer to your question. If not, then I have learned the way that I will use qmake until I find something better, because this is still a little bit ugly. I set up a demo project, this is my directory structure (files have extensions, folders do not):
MyProj
MyProj.pro
myproj-core
myproj-core.pro
globals.h
MyProjCore.h
MyProjCore.cpp
myproj-app
myproj-app.pro
main.cpp
We start with MyProj.pro as a subdirs project, which is the key to doing what you ask. Basically, instead of depending on other projects to specify debug/release and all sorts of other junk, you just set it on the one qmake file. It doesn't let you make only what you need, but it's the best solution I could come up with. Here are the contents:
TEMPLATE = subdirs
# Needed to ensure that things are built right, which you have to do yourself :(
CONFIG += ordered
# All the projects in your application are sub-projects of your solution
SUBDIRS = myproj-core \
myproj-app
# Use .depends to specify that a project depends on another.
myproj-app.depends = myproj-core
myproj-core.pro is your typical shared object library:
QT -= gui
TARGET = myproj-core
TEMPLATE = lib
DEFINES += MYPROJCORE_LIBRARY
SOURCES += MyProjCore.cpp
HEADERS += MyProjCore.h \
globals.h
myproj-app.pro is consumer application, where the little rebuild-when-needed trick is:
QT -= gui
TARGET = myproj-app
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
# Specify that we're lookin in myproj-core. Realistically, this should be put
# in some configuration file
INCLUDEPATH += ../myproj-core
# Link to the library generated by the project. Could use variables or
# something here to make it more bulletproof
LIBS += ../myproj-core/libmyproj-core.so
# Specify that we depend on the library (which, logically would be implicit from
# the fact that we are linking to it)
PRE_TARGETDEPS += ../myproj-core/libmyproj-core.so
SOURCES += main.cpp
I hope this solves your problem, as I know it solved mine!
EDIT: I made a file specifically for building the dependencies for me, I store it in a sibling folder of each of my projects (child of the MyProj in the directory structure specified above) called dependencies.pri:
# On windows, a shared object is a .dll
win32: SONAME=dll
else: SONAME=so
# This function sets up the dependencies for libraries that are built with
# this project. Specify the libraries you need to depend on in the variable
# DEPENDENCY_LIBRARIES and this will add
for(dep, DEPENDENCY_LIBRARIES) {
#message($$TARGET depends on $$dep ($${DESTDIR}/$${dep}.$${SONAME}))
LIBS += $${DESTDIR}/lib$${dep}.$${SONAME}
PRE_TARGETDEPS += $${DESTDIR}/lib$${dep}.$${SONAME}
}
So at the bottom of all the consuming applications, I can add the lines:
DEPENDENCY_LIBRARIES = myproj-core
include(../config/dependencies.pri)
This assumes that you are copying the libraries to some shared location and/or moving them around as needed, so my function might not work for you, but I figured I would add it to the solution.
I use the solution below. This works without the usage of an extra .pro file with subdir template.
TEMPLATE = app
TARGET = MyApp
PRE_TARGETDEPS = ../../libs/MyLib/MyLib.a
INCLUDEPATH += ../../libs/MyLib/include
HEADERS += src/MyApp.h \
../../libs/MyLib/incude/MyLib.h
SOURCES += src/MyApp.cpp
LIBS += ../../libs/MyLib/MyLib.a
MyLib.target = ../../libs/MyLib/MyLib.a
MyLib.commands = cd ../../libs/MyLib && make
MyLib.depends = ../../libs/MyLib/Makefile
QMAKE_EXTRA_TARGETS += MyLib
Check out this question: Force relink when building in QT Creator
Try adding something similar to this code to your pro file:
CONFIG(debug, debug|release) {
DESTDIR = ../../../bin/debug
OBJECTS_DIR = ./debug
}
else {
DESTDIR = ../../../bin/release
OBJECTS_DIR = ./release
}
Then you will have to specify the dependencies for each configuration:
CONFIG(debug, debug|release) {
LIBS += -L../../../lib/debug \
-L../../../bin/debug \
-llib1 \
-llib2
PRE_TARGETDEPS += ../../../lib/debug/liblib1.a \
../../../lib/debug/liblib2.a
else {
LIBS += -L../../../lib/release \
-L../../../bin/release \
-llib1 \
-llib2
PRE_TARGETDEPS += ../../../lib/release/liblib1.a \
../../../lib/release/liblib2.a
}
I had this problem when refactoring my project, after I moved in a new DLL (pqXDot) a reusable class (from pqGraphviz).
After adding a new DLL to my project, and adding the new DLL reference to others DLL and applications that needed it, I had in main .pro:
TEMPLATE = subdirs
SUBDIRS += \
pqConsole \
pqConsoleTest \
pqSource \
pqSourceTest \
fdqueens \
pqGraphviz \
pqGraphvizTest \
pqXDot
and the rebuild caused a linker error, because pqGraphviz, the DLL being restructured, can't find pqXDot, the new DLL.
It turns out it's sufficient to reorder the SUBDIRS list, moving the required DLL before the dependent one:
SUBDIRS += \
pqConsole \
pqConsoleTest \
pqSource \
pqSourceTest \
fdqueens \
pqXDot \
pqGraphviz \
pqGraphvizTest
For those that are interested into a template for your Qt/QML project, I have published one template on GitHub QmlAppTemplate.
I'd like to keep in my project some external files, let's say .txt ones.
Is there any special category for external files in project file (.pro) of Qt Creator?
Qt Creator, at least, uses an OTHER_FILES variable for .txt files and anything similar:
OTHER_FILES += test.txt
Adds "test.txt" to the "Project Files" pane in Qt Creator.
If you want to group your files a bit, what you can try is adding a separate .pri file such as "External.pri", including your external files from there, and then including the .pri file in your .pro:
Project.pro
HEADERS += someclass.h
SOURCES += main.cpp someclass.cpp
...
include(External.pri)
External.pri
OTHER_FILES += license.txt todo.txt
Which has the effect of creating a folder of sorts (called "External") in Qt Creator. If you have a bunch of external files it'll help keep things organized.