I'm interested in know what some of the fields in a standard QT application project file means ? Here is a example
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-02T11:06:19
#
#-------------------------------------------------
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = AV_Command
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
case.cpp \
interview.cpp \
parsexml.cpp
HEADERS += mainwindow.h \
case.h \
interview.h \
parsexml.h
FORMS += mainwindow.ui
I understand what most of this is doing, except these 2 lines.
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core gui xml means that the build process should expect to find and include QtCore, QtGUI and QtXML libraries for your project. If you don't use any XML (and especially don't use the XML headers) you can remove xml from that list.
On the flip side... if you wanted to add Qt's SQL stuff, you'd need to add sql to the list otherwise you would get linker errors complaining about missing definitions.
The greaterThan() compares QT_MAJOR_VERSION against 4. If true, then it adds widgets to the list of required QT libraries.
QT += core gui xml
Specifies what components of the Qt library you're using.
The second includes widgets depending on the version of Qt
Related
I have a project that I've written in VS2017 that has a lot of static libraries and I've got to the point where I want to start refining the gui. To make sure I can use Qt I made a test subdir program using the tips in https://www.toptal.com/qt/vital-guide-qmake, the https://wiki.qt.io/SUBDIRS_-_handling_dependencies example, the https://github.com/rainbyte/example-qmake-subdirs and https://github.com/219-design/qt-qml-project-template-with-ci/tree/6af6488d74e1dc97a8cef545080074055a696e9a projects as well as several of the similar questions here on SO.
This consists of a subdir project called "project" with 2 sub-projects "app" and "library". These are both simple QtApplications created using the New Subproject wizard, with all the files except for main.cpp removed from "app", everything left in except for main.cpp in "library", the point being to make sure mainwindow.h in "library" is referenced from main.cpp in "app". Despite trying every example I can find I'm still getting the "'mainwindow.h' file not found" error.
According to all the examples I could find you should only need to add a few lines (#) to the wizard-produced .pro files and add an additional .pri file to the "library" project;
Directory structure;
project/
project.pro
app/
app.pro
main.ccp
library/
library.pro
mainwindow.h
mainwindow.ccp
mainwindow.ui
library.pri
project.pro;
TEMPLATE = subdirs
TARGET = project ##
SUBDIRS += \
app \
library
app.depends = library ##
app.pro;
TEMPLATE = app ##
TARGET = app ##
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
SOURCES += \
main.cpp
include(../library/library.pri) ##
library.pro;
TEMPLATE = lib ##
TARGET = library ##
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += shared ##
CONFIG += lib_bundle ##
SOURCES += \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
DISTFILES += \
library.pri ##
and the added library.pri file;
LIBTARGET = library
BASEDIR = $${PWD}
INCLUDEPATH *= $${BASEDIR}/include
LIBS += -L$${DESTDIR} -llibrary
I know this has been asked many times already but I can find no definitive solution, or rather no-one seems to have bothered to post their working solution. I'd really appreciate any help with this, I'd love to be able to use Qt and escape the purgatory of win32 ui creation.
You have this:
INCLUDEPATH *= $${BASEDIR}/include
But you don't have directory named include anywhere, it seems. So probably remove the /include part from above.
I tried to create a simple Opencv application in Qt and upon running, the whole application is crashed. If I comment out the opencv related codes from the project, the project runs just fine.
What I did:
Downloaded the Qt 5.5.0 VS2013 64bit version
Downloaded the OpenCV 3.0
Downloaded the Cmake 3.3.2
There were already prebuilt binaries in when I extracted the Opencv package, But all tutorials on the net wanted me to recompile the source codes so did I. The package contains:
build
sources
created a new folder named mymade to hold the binaries next to the other two directories. So it now looks like this:
build
mymade
sources
Steps:
Fired up CMake, specified the source folder from the extracted files
and specified mymade as the output for binaries.
checked all options that had a opencv in their names, plus Qt! and configured it and subsequently generated the files.
This is the resulting contents:
So all is done and I now need to build the binaries. I opened OpenCV.sln and compiled the release and debug binaries. The dlls are placed inside bin directory, and the lib files are placed inside lib folder.
Now it's the time to configure the Qt projects .pro file, so I used the header files from build directory, and for libs I used the lib folder from mymade folder. This is the first configuration that I came up with, which compiles without any linker issues, but crashes just immediately.
The initial changes in project file :
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib
FORMS += mainwindow.ui
Doing this in project file as it was suggested by answers like this didn't do any good either:
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib
FORMS += mainwindow.ui
This fails as well:
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300
FORMS += mainwindow.ui
So what is the problem here?
Update
As it was pointed out by #Miki, Qt couldn't find the opencv dlls (the configs above were OK but), And to solve this problem, one only needs to add the directory containing dlls to the PATH variable, there you are good to go and everything should be fine now.
From the comments to question it turns out that the program didn't find OpenCV dll.
You can:
Copy the required dll in the same folder of the .exe
Add the folder containing the dll to the PATH. You need to restart Qt Creator for changes to take effect.
I have added qcustomplot.h/.c files to my Qt project. They are located in: "QT_PROJECT_DIR/QCustomPlot/".
Every time I use the designer in Qt Creator and build I get this error in ui_mainwindow.h:
error: ../../qcustomplot.h: No such file or directory
#include "../../qcustomplot.h"
This is of course true as it is located in: "QT_PROJECT_DIR/QCustomPlot/"
How do I change how Qt Designer auto generate this path?
If it helps, here is my .pro:
#-------------------------------------------------
#
# Project created by QtCreator 2014-01-12T00:44:44
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets widgets opengl printsupport
TARGET = Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
QCustomPlot/qcustomplot.cpp
HEADERS += mainwindow.h \
QCustomPlot/qcustomplot.h
FORMS += mainwindow.ui
CONFIG += mobility
MOBILITY =
Your include seems to be wrong:
#include "../../qcustomplot.h"
Since you do not add the QCustomPlot folder to your INCLUDEPATH, you would need to include the file as follows:
#include "QCustomPlot/qcustomplot.h"
Alternatively, you could change the INCLUDEPATH as follows:
INCLUDEPATH += $$QT_PROJECT_DIR/QCustomPlot/
and then you could include the header without the ugly ../../ relative reference as follows:
#include "qcustomplot.h"
It is a rule of thumb to avoid such relative include paths in the source and headers files themselves because the structure can change at any time, or may be different on a different machine, et al. It is better resolved by the buildsystem and include paths.
I met the same problem and have solved it.
It was caused by the path of qcustomplot object in xxx.ui.
Step 1: Open the ***.ui file which contains the qcustomplot item.
Step 2: Right click the qcustomplot item
Step 3: Double click the path of QCustomPlot, then change it to QCustomPlot/qcustomplot.cpp from ../../customplot.
Finally, the header of ui_***.h can auto include QCustomPlot/qcustomplot.cpp, instead of ../../qcustomplot.h.
My native language isn't English. If you find grammar mistake in my reply, please inform me. Let me correct it.
I'm doing some experimentation with Qt on the Mac just now but I can't get my widget to show up in my application.
I've used Qt on Windows before and to do this I would just reference the dll and promote a widget to my own class, using the appropriate header file. I've tried the same on Mac but just get a blank screen.
The steps that I went through were to build the library (which gives me several files, *.dylib, *.1.dylib, *.1.0.dylib and *.1.0.0.dylib) and use the "Add Library..." function on my main application project. I'm not sure what all of these different dylibs are for but I have tried copying all of them into /usr/lib and the Contents/Frameworks folder inside my application bundle.
Can anyone shed any light on what might be going wrong and the key differences between doing this simple test on Windows and Mac?
Thanks,
Alan
Edit: Added code for project file
#-------------------------------------------------
#
# Project created by QtCreator 2013-10-02T19:59:44
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestApp
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-TestLibrary
Desktop_Qt_5_1_0_clang_64bit-Debug/release/ -lTestLibrary
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-TestLibrary
Desktop_Qt_5_1_0_clang_64bit-Debug/debug/ -lTestLibrary
else:unix: LIBS += -L$$PWD/../build-TestLibrary-Desktop_Qt_5_1_0_clang_64bit-Debug/
lTestLibrary
INCLUDEPATH += $$PWD/../TestLibrary
DEPENDPATH += $$PWD/../TestLibrary
i build a C++ library with qt creator.
qt builds for me in debug folder 3 files:
'1. libSerialize.a' and '2. Serialize.dll' and 'serialize.o' .
now i want to add this library to another qt project.
how can i do that?.
how can i include that library? .
where should i copy those? .
which one is necessary? .
this is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = get_send_array
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp \
student.cpp
HEADERS += widget.h \
student.h
so thanks, please help me.
Use:
win32:LIBS += /path/to/the/lib/Serialize.dll
unix:LIBS += -L/path/to/the/lib/ -lSerialize
Serialize.dll is a windows dynamic load library, and libSerialize.a is an ar archive (you may reffer to it as a static library) and usually used in *nix systems.