QtCreator unable to find Qxt headers on Linux? - c++

I'm working on a Qt5/QtQuick/QML application that's supposed to use QxtGlobalShortcut for hotkey control when the application is hidden or out of focus. I've been developing it using QtCreator on Linux, and I'm not entirely familiar with Linux development so I may have missed something simple.
First off, I tried cloning the master branch of the Qxt git repo from here. But for some reason ./configure failed to create a makefile according to an error that I was getting from make and make install. I'm not very experienced in building other people's projects/libraries from source, and the output I was getting from ./configure wasn't specific enough for me to figure out what was going on..
So instead, I decided to grab libqxt-dev from (X)ubuntu's APT repo. After it finished installing I added these lines to the bottom of my QtCreator project file:
INCLUDEPATH = usr/include
CONFIG += qxt
QXT += core gui
After setting up a basic global shortcut based totally off the Qxt documentation's example. I got a few compilation errors. First of all, the Qxt seem to use:
#include <QxtGlobalShortcut>
But QtCreator couldn't find that file, so I changed it to this:
#include <qxt/QxtGui/QxtGlobalShortcut>
Now it could find the Global Shortcut class header, and QtCreator stopped grumbling at me. Unfortunately, upon compilation QtCreator shot out this error message:
/usr/include/qxt/QxtGui/qxtglobalshortcut.h:28: error: qxtglobal.h: No such file or directory
I think this is caused by a problem in my project's INCLUDE path or something, but even having tried changing my projects INCLUDE path to this:
INCLUDEPATH = usr/include
usr/include/qxt/QxtCore
usr/include/qxt/QxtGui
CONFIG += qxt
QXT += core gui
I still get the same error message that QxtGlobal.h (which is being #included in QxtGlobalShortcut.h) can't be found..
So, I'm really not sure what I've done wrong, and I'm out of ideas about how to fix this.
Hopefully someone can help me understand what step I've skipped so that I can continue coding! Thanks!
EDIT: Here's what I have for my entire Qt project .pro file:
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp \
Gamepad.cpp \
Script.cpp \
System.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
Gamepad.h \
Script.h \
System.h
LIBS += -L/usr/lib -lSDL2
CONFIG += qxt
QXT += core gui
Everything before LIBS was automatically generated by QtCreator for my project. I added the LIBS, CONFIG, and QXT elements as per the user instructions for SDL2 and Qxt.

This is a big problem here:
INCLUDEPATH = usr/include
1) You are using relative path from the current working directory, so not /usr/include from the root of the filesystem.
2) You are deleting everything in the INCLUDEPATH because you set rather than append with +=.
3) It is unnecessary to add that line anyway since /usr/include will be looked up by default.
4) Even if it was not, you have #include "qxtglobal.h" instead of #include <qxtglobal.h>.
I would suggest to delete that line and then it should just work.

Related

build a standalone exe file form a QT+openCV project running in QT Creator

I just recently programmed a project in QT Creator framework which both uses QT libraries such as QT_Widget and also openCV libraries such as openCV_tracking .
my project includes .ui , .pro , main.cpp and some classes with .h and .cpp files.
my .pro file is :
QT += \
core gui \
concurrent widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Version7
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += \
c++11 \
cmdline
SOURCES += \
main.cpp \
mainwindow.cpp \
videoprocessor.cpp \
robottracker.cpp \
robotdetector.cpp \
obstaclesdetector.cpp \
pathcapture.cpp
HEADERS += \
mainwindow.h \
videoprocessor.h \
robottracker.h \
robotdetector.h \
obstaclesdetector.h \
pathcapture.h
FORMS += \
mainwindow.ui
# including openCV needed files
INCLUDEPATH += E:\\MyOpenCV\\install\\include
INCLUDEPATH += C:\\openCV\\opencv\\build\\include
LIBS += -LE:\\MyOpenCV\\install\\x64\\vc15\\lib \
-lopencv_tracking430
LIBS += -LC:\\openCV\\opencv\\build\\x64\\vc15\\lib \
-lopencv_world430
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
it runs in QT creator with no problem ; but now i wanna share it with my team and for that I want to build a standalone exe file from it which statically links all libraries used in project.
can someone please guide me how can I do that with QT Creator or some other options?
in the internet there were some suggestions but none worked .
I tried this a while ago but eventually gave up, although it definitely is possible.
The reason Qt hides how to do it so much is that they much prefer that people dynamically link to their libraries as it both allows users to update/change the Qt dll's as they please and (which I think is the real reason) it makes it more obvious that a developer is using their suite.
I will guide you in the direction I think should be taken, but I am not too sure how successful you will be unfortunately.
First you need to build the actual Qt library statically. I will assume you are using the MinGW shipped with Qt Creator as your compiler. According to the following tutorial https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW , you can download the following powershell script (ensure you have powershell installed): https://sourceforge.net/p/qtlmovie/code/ci/v1.2.16/tree/build/windows-build-qt-static.ps1?format=raw. As long as you have Qt installed under C:\Qt, and a subdirectory called "Static" in this folder, you should be able to simply run this script and wait for Qt to build into that folder.
Secondly, you need to link against the Qt libs in your application. Open Qt Creator, go to Tools > Options > "Build & Run". The Qt tutorial says the following:
Go to tab "Qt Versions". In the "qmake location" table, there must be an "Auto-detected" part and a "Manual" part. In the "Auto-detected" part, there should be one line named "Qt 5.5.0 MinGW 32bit C:\Qt\Qt5.5.0\5.5\mingw492_32\bin\qmake.exe". The "Manual" part is initially empty.
Click "Add", browse to C:\Qt\Qt5.5.0\bin and select "qmake.exe". The version name is automatically set to "Qt 5.5.0 (5.5.0)". You should set a more meaningful name such as "Qt 5.5.0 MinGW Static 32bit"
Then go to tab "Kits". Again, there must be an "Auto-detected" part and an initially empty "Manual" part. Click "Add". Set a meaningful name such as "Desktop Qt 5.5.0 MinGW Static 32bit". In the "Qt version" field, select your static environment, named "Qt 5.5.0 MinGW Static 32bit" if you followed the above advice.
Click "Add Kit" in the upper left corner and select your static kit, named "Desktop Qt 5.5.0 MinGW Static 32bit" if you followed the above advice.
That should be it. Unfortunately I'm unable to try it out by myself, but that should be the general procedure. A lot of the tutorials seem long-winded, but generally if you follow them step-by-step they work out in the end.
Also, do note that they didn't refer to the "static" directory in the above instructions. I believe this is incorrect, and that is what they are actually referring to, so maybe give that a try instead, although I'm not sure.
Good luck!

How to make makefile generated by Qt without qmake dependency

I use Qt creator in linux to make my non-Qt c++ project. I find that Qt creator would make a makefile for me. I want to move all the project into a computer without any qt or qmake, but I cannot really edit the makefile myself. As I google that someone says add a CONFIG -= qt flag can make a pure g++ makefile without any qt component but actually not.
the pro file in my project is like this:
QMAKE_LFLAGS += -no-pie
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += /home/MyName/opencvBuild/install/include/opencv4/
LIBS += -L/home/MyName/opencvBuild/install/lib/ \
-lopencv_core \
SOURCES += \
main.cpp \
helloopencv.cpp
HEADERS += \
helloopencv.hpp
and the makefile generate thousands of Qt dependencies like:
.....
###### Files
SOURCES = ../HelloOpenCV/main.cpp \
../HelloOpenCV/helloopencv.cpp
OBJECTS = main.o \
helloopencv.o
DIST = ../Qt/5.12.0/gcc_64/mkspecs/features/spec_pre.prf \
../Qt/5.12.0/gcc_64/mkspecs/common/unix.conf \
../Qt/5.12.0/gcc_64/mkspecs/common/linux.conf \
../Qt/5.12.0/gcc_64/mkspecs/common/sanitize.conf \
../Qt/5.12.0/gcc_64/mkspecs/common/gcc-base.conf \
.....
now when I call make command in terminal it would automatically link to qmake.
I don't want any "Qt" in my makefile. What should I do?
These are not "Qt"-dependencies, but rather "qmake"-dependencies: it's a list of files which qmake had processed in order to generate your Makefile. Stuff like gcc-base.conf is needed for some common gcc options, sanitize.conf for a bunch of -fsanitize= options, and so on.
Thus, it's the list of the files your Makefile itself depends on (used for auto-regeneration and such). Of course, if you don't intend to ever regenerate Makefile with the help of qmake, you can just delete all these lines at once.
You complain that despite of having CONFIG-=qt in your .pro, there is still a bunch of qt_config.prf and other such files mentioned in that list. This is true, however qmake startup scripts designed precisely in this way: first, all Qt-related stuff is unconditionally preconfigured; then the user project is processed; and then, only if CONFIG += qt, the relevant Qt stuff finally becomes enabled.
Just for fun, you can mess with qmake startup code: go to <prefix>/share/qt5/mkspecs/linux-g++-64 (or whatever your QMAKE_SPEC is); open the file qmake.conf; comment out the last string: #load(qt_config). Now your CONFIG -= qt project should be processed okay, but the resulting Makefile will be significantly smaller. But the price is that qmake cannot do Qt-enabled projects anymore (well, in fact, you can add load(qt_config) on top of your .pro file and it may even work - no warranties of any kind, of course ;-).

Qt Creator error endless loop

When I try to create a project which was developed by someone working in a different country and timezone I keep getting the following error in my console. He had mentioned this problem is because of the Data/Time being different from his computer to mine. I'm not sure if that is true, if it is, there has to be a solution for that without having to change my computer time to match his. I'm not sure what else to post that would be helpful in trouble shooting this, if there is just let me know and I'll update. I'm a bit new to C++/Qt Creator. Why is this happening. It seems to never finish, it just endlessly prints this to the console.
Compile Output Console
Running steps for project Nexus...
Configuration unchanged, skipping qmake step.
Starting: "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe"
C:\Qt\5.5\mingw492_32\bin\qmake.exe -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" -o Makefile ..\Nexus\Nexus.pro
C:\Qt\5.5\mingw492_32\bin\qmake.exe -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" -o Makefile ..\Nexus\Nexus.pro
C:\Qt\5.5\mingw492_32\bin\qmake.exe -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" -o Makefile ..\Nexus\Nexus.pro
C:\Qt\5.5\mingw492_32\bin\qmake.exe -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" -o Makefile ..\Nexus\Nexus.pro
General Message Output Console
Warnings while parsing QML type information of C:/Qt/5.5/mingw492_32/qml:
<dump of C:\Qt\5.5\mingw492_32\qml>:1:24: Reading only version 1.1 parts.
<dump of C:\Qt\5.5\mingw492_32\qml>:10:5: Expected only Component and ModuleApi object definitions.
Pro file
#-------------------------------------------------
#
# Project created by QtCreator 2016-02-29T21:37:32
#
#-------------------------------------------------
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
include(core/core.pri)
include(node/node.pri)
include(librarybox/librarybox.pri)
include(blockeditor/blockeditor.pri)
include(propertyeditor/propertyeditor.pri)
include(lib/lib.pri)
TARGET = Nexus
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui \
virtualnamepropertyitem.ui
RESOURCES += \
nexus_resources.qrc
RC_FILE = nexus.rc
This can happen if your .pro file (or any other file) has a timestamp from the future. The Makefile generated by qmake contains a rule that will generated the Makefile anew when its older than the .pro file. Since the new Makefile is still older than its counterpart from the future, this will go on till you actually reach the correct time.
There are two ways to get rid of this behavior:
Wait till the .pro file's timestamp is in the past (not recommended)
Edit the .pro file. Even a trivial edit like a new comment should be enough.
Had the same problem with latest version of QtCreator (3.6.1 with Qt 5.6.0).
Answer proposed by "Zeta" did not help.
Disabling "Shadow build" in project options fixed the problem for me. That's a good workaround.
Finally shorten file names (somes where huge) to fix the issue:
Shortened project names (.pro) (file name and path, removed a few caracters)
Shortened resources names (.qrc) (file name and path, removed a few caracters)
Issue then disappeared (even with shadow build, it's probably related as shadow-builds are using an output folder with a very long name).
There's apparently a bug when file paths are too long (>~170, found a post on a forum reporting that).
An alternative is also to change the pattern used by QtCreator for shadow builds. This can be modified from the QtCreator options and you can then make the name shorter, this is another way to quickly and easily fix the issue.
I wrote a python script that loops through recursively through all the files of the project and simply just resaves the files. That updated the timestamp and corrected the QMake Infinite loop. It now compiles correctly.

dyld: Library not loaded: myOwnLibrary

Context
I'm developing an app in Qt with Qt Creator in OS X. Right now my file organization is a mess (every file is the same folder) so I've decided to move to another project structure that also allows me to also run unit tests.
What have I tried
Following this blog entry I tried to create the same project (just for testing purposes).
Problem
Everything compiles but when executing it gives an error Library not loaded.
I thought that maybe I was doing something wrong so I cloned the example repo and try it again with a working example. But it gives me the same error:
dyld: Library not loaded: libmyapp.1.dylib
Referenced from: /Users/(my build folder)/app/app
Reason: image not found
The example is supposed to be right. The only changed I made is to remove the test subdir as I haven't installed yet UnitTest++ so my .pro file is like this:
TEMPLATE = subdirs
CONFIG+=ordered
SUBDIRS = \
src \
app
app.depends = src
OTHER_FILES += \
defaults.pri
Am I doing something wrong? Is there any step that I forgot?
Edit 1:
Creating manually a Frameworks folder and adding the libmyapp.1.dylib inside the bundle makes the app work. But I think this step should be done automatically
Edit 2:
I've tried to run macdeployqt as suggested. It seems that the app is trying to get the library from the system path instead of the provided:
macdeployqt app.app
ERROR: no file at "/usr/lib/libmyapp.1.dylib"
I have done the following to get the correct dependencies on a lib in the executable...
This code in the application pro file sets dependencies and also places the files directly into the Contents/Framework folder inside bundle (I chose to make the executable do all the work)
# to get the dependencies
INCLUDEPATH += ../libmyapp
macx {
LIBS += ../libmyapp/libmyapp.1.dylib
PRE_TARGETDEPS += ../libmyapp/libmyapp.1.dylib
MY.path = Contents/Frameworks
MY.files = ../libmyapp/libmyapp.1.dylib
QMAKE_BUNDLE_DATA += MY
}
Alternatively you can make your lib become a framework .. 2 options in this post:
How to create a Bundle Library (mh_bundle) with qmake on Mac OS X?
Would be good to read on the process of deploying an app on OS X... The tool trojanfoe was thinking of, for deploying qt apps, is called macdeployqt
Working with bundles of C++ programs with dependencies on Mac OS X can be a real pain. A workaround until you actually need to ship your app as a bundle is tell Qt not to create a bundle at all. Add the following to your app.pro file:
CONFIG -= app_bundle
Then you may add the dylib to the output directory yourself and it should hopefully work fine.
Another option is to set/add the environment variable LD_LIBRARY_PATH in the Run settings for your project in Qt Creator to point to the path where your compiled dylib is located.
I'm not sure that the above works, but those are my best guesses from earlier experience with similar issues. Also, make sure you are using the newest versions of Qt and Qt Creator.

Problem installing QCA-OSSL (part of the Qt Cryptographic Architecture) plugin on Windows 7

I have been trying to use QCA (Link) on my Windows PC for a couple of days now, works fine on my linux box, just can't get it working with Windows.
So i followed all the instructions for installing QCA and then the ossl plugin for QCA. The QCA works fine but for some reason the plugin isn't showing up in my Qt Creator nor am I able to use some of the functions in the plugin.
I used the qcatool2.exe that comes with QCA to check my plugins using
qcatool2 plugins --debug
and get this error message:
plugin: qca-ossl2.dll: failed to load: The plugin 'C:/Qt/2010.05/qt/plugins/crypto/qca-ossl2.dll' uses incompatible Qt library. Expected build key "Windows mingw debug full-config", got "Windows mingw release full-config"
Now this seems to me as if qt requires the plugin to be compiled in debug mode (as to get the build key to contain debug rather than release) so I added
CONFIG += debug
to my plugin's project file and ran qmake and mingw32-make as usual but this seems to have had no effect.
My project file for the plugin is now:
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
load(winlocal.prf)
isEmpty(WINLOCAL_PREFIX) {
error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
}
OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
CONFIG += debug
Has anyone got any ideas? If you need anymore details just ask, I've tried to be as thorough as possible. Thanks
Tom
I've been struggling with a similar situation: qca-ossl builds fine on linux and not at all on windows. I just hit a breakthrough which might help you as well.
Versions and Patches
qtsdk-2010.05
qca-2.0.3
qca-ossl-r1190163 (from the repository)
openssl-1.0.0b
First of all, if you're using a newer version (0.9.7+, I think) of OpenSsl, you may need to use the qca-ossl version from the repository since it patches some incompatibilities. I also needed to comment out some lines in the new qca-ossl.cpp file dealing with SHA224, SHA256, SHA384, and SHA512 to avoid build errors. I'm using qca-ossl for the ciphers, so I'm not worried about hashing and didn't investigate the errors very much.
Fixing It
The windows build problems were many fold for me, but most of them stem from the shoddy build setup for the windows version of the plugin. It's nice having a little configure script for the linux side of things, but what about windows? We need to do a little extra work.
Some of this extra work is because I've chosen non-standard locations for the support libraries of my application. Qca and OpenSsl both exist within the project's directory structure in a libraries/ directory. My guess is that you've done something similar if you are trying to cross compile your application, but even if you didn't the following should help.
Finding OpenSsl
Qca-ossl wont build very well if it can't find the library it's supposed to connect to... :) So let's specify directly where it is. Comment out the lines relating to winlocal.prf and the changes that stem from it in qca-ossl.pro. We will directly specify where to find openSsl.
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
# Rather than rely on the winlocal.prf file, we will specify the location of the openssl
# by hand when running qmake.
#
# load(winlocal.prf)
# isEmpty(WINLOCAL_PREFIX) {
# error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
# }
#
# OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
Now we have direct access to the $$OPENSSL_PREFIX environment variable in the .pro file. We can set it when we call qmake by doing the following.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b"
You should be able to use backward slashes or forward slashes. Here I choose forward since Qt has deprecated them since 4.7.
Alternatively, you could set the OPENSSL_PREFIX variable directly in the .pro file.
Finding Qca
After comparing the unix and windows makefiles for qca-ossl, oddly enough, it never includes the qca libraries for building or linking! ?!?! This led to an "Undefined interface" error on the Q_INTERFACES(QCAPlugin) line of the opensslPlugin class definition at the end of qca-ossl.cpp.
To avoid this, we will need to explicitly define the include and library paths by hand. Expanding on the qmake line from the last section the final qmake line is as follows.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b" "INCLUDEPATH+=C:/path/to/qca-2.0.3/include/QtCrypto" "LIBS+=-LC:/path/to/qca-2.0.3/lib -lqca2"
"Installing" Qca-ossl
After running the qmake line above and running a plain ol' make, you'll need to install Qca-ossl. You can copy the resulting dll from the lib/ directory to your Qt's plugins directory, which if you're using my versions defaults to C:\Qt\2010.05\qt\plugins\crypto. Alternatively, you can move it to a crypto directory that's at the root level of your project's directory structure such as C:\path\to\my\project\crypto.
I hope this helps!
Actually, you can try this tutorial QCA+OpenSSL on Window. It's work well.
By the way, I can make use of QCA with AES 256 on Window. But i can't use it on Symbian. Any idea to do it?
Related Post