Qt one project knows the other ones classes - c++

Have tried to "link" two projects together. So one project knows the other ones classes. One project is the program, the other project is a test program for the first one. So i want the test program to have access to the other ones classes so i can test them.
Both projects are sub projects.
They are placed under header project, there folders are beside each other.
Have tried many different ways but with no result.
Head.pro
TEMPLATE = subdirs
SUBDIRS += \
MT \
Test
MT.pri same folder as the program.
INCLUDEPATH += $$PWD
SOURCES += $$PWD/parser.cpp
HEADERS += $$PWD/parser.h
MT.pro
QT += core bluetooth gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MT
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG += mobility
SOURCES += main.cpp\
mainwindow.cpp \
t.cpp \
parser.cpp \
devicediscovery.cpp
HEADERS += mainwindow.h \
parser.h \
devicediscovery.h \
t.h \
typedefs.h
FORMS += mainwindow.ui
MOBILITY =
INSTALLS += target
DISTFILES += \
MT.pri
Test.pro
include(../MT/MT.pri)
QT += widgets testlib core bluetooth gui
TARGET = tst_testmttest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
HEADERS += parser.h
SOURCES += tst_testmttest.cpp / parser.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"

Use in Test Project:
include(Path/to/OtherProject/file.pri)
Use in Other project
QT += xml
INCLUDEPATH += $$PWD
SOURCES += $$PWD/parser.cpp
HEADERS += $$PWD/parser.h
works fine

Related

Why am i getting this error with using opencv on QT windows?

I am having this issue where I have installed OpenCV to be used on QT creator. I have typed some basic testing code "cv::Mat img = imread("test.png");" this does not compile as it gives me 4 errors that i have shown in the image.
------------------------.Pro File--------------------------------------
QT += core gui
QT += testlib
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
editor.cpp \
image.cpp \
linked_list.cpp \
main.cpp \
mainwindow.cpp \
tests.cpp
HEADERS += \
editor.h \
image.h \
linked_list.h \
mainwindow.h \
node.h
FORMS += \
editor.ui \
mainwindow.ui
INCLUDEPATH += \
D:/boost
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -LD:/opencv/build/x64/vc15/lib/ -lopencv_world420
else:win32:CONFIG(debug, debug|release): LIBS += -LD:/opencv/build/x64/vc15/lib/ -lopencv_world420d
else:unix: LIBS += -LD:/opencv/build/x64/vc15/lib/ -lopencv_world420
INCLUDEPATH += D:/opencv/build/include
DEPENDPATH += D:/opencv/build/include

Can't step into/break on my code with qt creator

I have created a project in qt creator with multiple subdirs and am deploying/running it on a beaglebone. Compiles fine, deploys fine, etc.
My issue is that when I try to debug, the only files I can set breakpoints in or step into are those in the same subdir where main.cpp is. Just to test, I duplicated the project with a flat folder structure and can set breakpoints and step into everything.
When the debugger starts up, the debug log tries to set the breakpoints and fails seemingly because it can't find the .cpp files:
"No source file named projectdir/dir1/myclass.cpp.\n"
8045^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="",pending="\"projectdir/dir1/myclass.cpp\":7",times="0",original-location="\"fullpathofprojectdir/dir1/myclass.cpp\":7"}
Whereas it says this for breakpoints in main:
8046^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x0001831c",func="main(int, char**)",file="projectdir/dir2/main.cpp",fullname="fullpathofprojectdir/dir2/main.cpp",line="27",thread-groups=["i1"],times="0",original-location="fullpathofprojectdir/dir2/main.cpp:27"}
Additionally, myclass.cpp doesn't show up in the source files panes either. How can I resolve this?
Here is the setup of my *.pro files:
Top level project file:
TEMPLATE = subdirs
SUBDIRS += \
dir1 \
dir2
unix {
target.path = /home/debian
INSTALLS += target
}
Project file of library (dir1, myclass.cpp, etc):
QT -= gui
TARGET = Common
TEMPLATE = lib
DEFINES += COMMON_LIBRARY
SOURCES += \
myclass.cpp
HEADERS += \
common_global.h \
myclass.h
unix {
target.path = /home/debian/lib
INSTALLS += target
}
CONFIG += debug
Project file containing main:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test
TEMPLATE = app
SOURCES += \
main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Common/release/
-lCommon
else:win32:CONFIG(debug, debug|release): LIBS += -
L$$OUT_PWD/../Common/debug/ -lCommon
else:unix: LIBS += -L$$OUT_PWD/../Common/ -lCommon
INCLUDEPATH += $$PWD/../Common
DEPENDPATH += $$PWD/../Common
target.path = /home/debian
INSTALLS += target
Let me know if there's any other relevant data I forgot to provide. Qt Creator version is 4.5.0 and I'm running it on a 64 bit VM of ubuntu 16.04 if that's relevant.

Qmake -= operator not working correctly

I have a Qt project which I want to include all of my source files bar one.
SOURCES += $$files(*.cpp)
SOURCES -= excluded.cpp
I have tried using the wildcard directly
SOURCES += *.cpp
The strange thing is that if i print out the value of SOURCES the file is not printed, however it is still built with the rest of the project:
message($$SOURCES) # doesn't show excluded.cpp
Any help would be greatly appreciated!
EDIT:
Here is my full .pro:
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += $$files(../compiler/src/*.cpp)
SOURCES -= ../compiler/src/main.cpp
SOURCES += test.cpp
INCLUDEPATH = ../compiler/include
HEADERS += $$files(../compiler/include/*.h)
LIBS += -lgtest -lgmock -pthread
QMAKE_CXXFLAGS += -std=c++1z

QT Creator: How to generate the library and testing executable for a custom widget

There is the following files:
MyWidget
|- MyWidget.cpp
|- MyWidget.hpp
|- MyWidget_UnitTest.cpp
I would like to generate at once following files:
MyWidget.dll (or equivalent for non windows OS)
MyWidget_UnitTest.exe (or equivalent for non windows OS)
So it is easy to test the widget for bugs, but also to have the result inside further widgets or projects.
I tried to manipulate the .pro file, but with no success:
# ONLY TESTING UNIT
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyWidget_UnitTest
TEMPLATE = app
SOURCES +=\
MyWidget.cpp \
MyWidget_UnitTest.cpp
HEADERS += \
MyWidget.hpp
CONFIG += c++11 -Wall
#ONLY LIB
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyWidget_UnitTest
TEMPLATE = lib
SOURCES +=\
MyWidget.cpp \
MyWidget_UnitTest.cpp
HEADERS += \
MyWidget.hpp
CONFIG += c++11 -Wall
CONFIG += dll
I am unable to merge both into a single project.
Possibly more result could be added: static vs dynamic lib, etc.
Use the SUBDIRS project organization.
project_dir/
src/
your_dll/
... sources, headers ...
your_dll.pro
your_exe/
... sources, headers ...
your_exe.pro
project_dir.pro
project_dir.pro
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += src/your_dll
SUBDIRS += src/your_exe
your_exe.depends = your_dll
your_exe.pro
TARGET = your_exe
TEMPLATE = app
QT += widgets
LIBS += -L$${YOUR_DLL_PATH} -lyour_dll
etc...
your_dll.pro
TARGET = your_dll
TEMPLATE = lib
QT += widgets
etc...
Now when you build, the DLL and EXE will be built, and the EXE will be linked to the DLL.
Use different CONFIG flags:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES +=MyWidget.cpp
HEADERS += MyWidget.hpp
CONFIG += c++11 -Wall
testmode {
# ONLY TESTING UNIT
TARGET = MyWidget_UnitTest
SOURCES += MyWidget_UnitTest.cpp
TEMPLATE = app
}
libmode {
#ONLY LIB
TARGET = MyWidget
TEMPLATE = lib
CONFIG += dll
}
To build both:
qmake "CONFIG+=libmode"
make
qmake "CONFIG+=testmode"
make

Qt cannot open Lib file - LNK1104 Cannot open file 'DbManager.lib'

I am using QT Creator 2.7.0 based upon QT 5.0.2 on a Windows 7 machine and attempted to create a subdirs project with three sub-projects.
Project_Dir
- DbManager
- Gui
- Build
Using the example here How to use qmakes subdirs template, I created the Project files listed below, however, upon building I keep getting the error LNK1104 Cannot open file 'DbManager.lib'
My search usually yeilds results for Visual Studio type fixes, but no QT fixes
Project.pro
TEMPLATE = subdirs
SUBDIRS += \
DbManager \
Gui
CONFIG += ordered
SUBDIRS += Build
DbManager.pro
! include( ../common.pri ) {
error( Couldnt find the common.pri file! )
}
HEADERS += dbmanager.h
SOURCES += dbmanager.cpp
Gui.pro
! include( ../common.pri ) {
error( Couldnt find the common.pri file! )
}
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = target
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Build.pro
TEMPLATE = app
DEPENDPATH += ../Gui
INCLUDEPATH += ../Gui
DEPENDPATH += ../DbManager
INCLUDEPATH += ../DbManager
LIBS += -L../DbManager -L../Gui -lDbManager -lGui
SOURCES += main.cpp
TARGET = ../OptionsTrader
QT += widgets
The following "Common.pri" file, was also included:
INCLUDEPATH += . ..
WARNINGS += -Wall
TEMPLATE = lib
UI_DIR = uics
MOC_DIR = mocs
OBJECTS_DIR = objs
I got the same problem before, and I just copy the lib file into the project working directory,it worked.