Qt will not link anything - c++

I have tried this both on Ubuntu Linux and on Windows. I can not get Qt to link any of its libraries or any external libraries, I have tried just about every LIBS += -Lpath/to/lib -llib and INCLUDEPATH += path/to/include/files combination possible in my .pro file:
QT += opengl
TARGET = QtOpenGLExample
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
GLExampleWidget.cpp
HEADERS += GLWidget.h
LIBS += -L /usr/lib/ -llibQtOpenGL.so.4.6.2
I noticed this being a problem when I clicked "Open GL" in the project creator and it did not work then (even after I tried messing around in the .pro), before I just thought I was doing something stupid when I tried to link SFML 1.6.
P.s Does it have to do with were my project is located?:
/home/aperson/Projects/ComputerProgramming/C++/OpenGLExample/

It should not be
LIBS += -L /usr/lib/ -llibQtOpenGL.so.4.6.2
but
LIBS += -L /usr/lib/ -lQtOpenGL
Because for the linker -lfoo means libfoo.so (and it should be able to find the right version of the file, so you don't need to tell about 4.6.2)
Probably, you don't even need a special LIBS since opengl is mentioned in the QTline. But you should be sure that the libqt4-opengl-dev package is installed.

Taken from QtOpenGL Module :
The Qt OpenGL module makes it easy to use OpenGL in Qt applications. It provides an OpenGL widget class that can be used just like any other Qt widget, except that it opens an OpenGL display buffer where you can use the OpenGL API to render the contents.
To include the definitions of the module's classes, use the following directive:
#include <QtOpenGL>
To link against the module, add this line to your qmake .pro file:
QT += opengl
You might need to link to your opengl library. This should do :
LIBS += -lGL

It is because you have told qmake that you are creating a console application in your .pro file making it ignore all the GUI libraries. So get rid of the CONFIG += console line.

The project file you have seems OK. QMake should generate the corrent -l -L command for you. IMHO that is not the problem.
Are you missing the opengl/Qt4 package? Its called libqt4-opengl-dev on Ubuntu and Debian.
See
http://packages.debian.org/sid/libqt4-opengl-dev
http://packages.ubuntu.com/search?searchon=names&keywords=libqt4-opengl-dev
Type this on your shell to check and install the package if needed.
$ dpkg -l | grep opengl
ii libqt4-opengl 4:4.8.0-1ubuntu11 Qt 4 OpenGL module
$ aptitude install libqt4-opengl-dev

Related

Fail to link Pylon(Basler) SDK with Qt on Mac

I am trying to link Qt with the Pylon camera SDK in a Qt Creator project.
I install the pylon Camera Software Suite app from this pylon for OS X and the pylon framework is install at /Library/Frameworks/pylon.framework.
I first follow the pylon Programmer's Guide which is installed with the app to link the pylon with Xcode. It works perfectly.
Then I try to link with my Qt Project. I add this in the .pro file:
mac: LIBS += -F/Library/Frameworks/ -framework pylon
# add GenICam because pylon Programmer's Guide do so
INCLUDEPATH += /Library/Frameworks/pylon.framework/Headers/GenICam
DEPENDPATH += /Library/Frameworks
But this doesn't work. Qt cannot find the header files.
I also try:
QMAKE_LFLAGS += -F/Library/Frameworks/
LIBS += -framework pylon
as said in the document Using Frameworks. But still not working. Anyone help me to fix this? Thanks.
Update:
Weird is that Qt can detect auto-complete of the header files but when build it says no such file found.
I just answered this here:
A) If you are compiling this Pylon framework with source then In these cases you need source code installation, you need to go to your
Pylon source directory, e.g.:
<path-to-pylon>/src/include/
You can locate the directory where PylonIncludes.h is installed by
runing the following command:
find <path-to-Pylon> -name PylonIncludes.h
Once you locate the directory e.g. lets say
/Users/kevin/Pylon5.5 then you include add the following line in your
CMAkeLists.txt
INCLUDEPATH += /Users/kevin/Pylon5.5/src/include/
B) If you have binary framework itself then you can workaround by copying all headers to tmporary location under pylon/<all-headers>
cp -rf /Library/Frameworks/pylon.framework/Versions/A/Headers/* /tmp/pylonHeaders/pylon/ Then use following in .pro file
INCLUDEPATH += /tmp/pylonHeaders
LIBS += -framework pylon
There is an automatism in Xcode when you insert a framework it includes the header directory of the used frameworks automatically.
In your case, simple add this line and the compiler will find the pylon headers.
QMAKE_CXXFLAGS += -F/Library/Frameworks
I hope this will help you. With best regards

QT .pro file: How to change default include path for MAC frameworks

My .pro file looks like this:
QT += core gui widgets
SOURCES += a.cpp
HEADERS += a.h
FORMS += a.ui
#Locally compiled Qt framework. Qt/out/{QtCore.framework,QtNetwork.framework..}
QMAKE_LFLAGS += -L./Qt/lib/
QMAKE_CXXFLAGS += -F./Qt/lib/
macx {
QMAKE_MAC_SDK = macosx10.9
LIBS += -framework QtCore -framework QtNetwork -framework QtGui -framework QtWidgets
}
I want to use frameworks compiled locally, but QT5.5 automatically includes framework from QT5.5.0 install directory ... I see a.cpp compiling with following include switch:
-I/Users/banana/Qt5.5.0/5.5/clang_64/lib/QtWidgets.framework/Headers
I tried resetting INCLUDEPATH = in .pro file in hopes that it resets the default include path and added proper INCLUDEPATH += ./Qt/lib but it doesn't work.
Using MAC, OS X 10.10.2
The Qt installation that gets used will be determined by which qmake you run. If you have multiple versions of Qt installed (e.g. one you built from sources yourself and one provided by the system or by a Qt Creator install), you need to ensure you are running the qmake from the Qt you want to use. You should be able to verify this from the command line fairly easily. If you are using an IDE like Qt Creator and are having issues getting the right Qt selected, try building from a command line first to verify that you can get the right Qt that way as a first step. If building things from the command line where you have absolute control over which qmake is used still doesn't work, then this would suggest the qmake you are trying to use isn't behaving in the expected way.

How to create Qt executable for linux machines

I have created a project using Qt 5.3. I want this project to be executable on other linux machines, so I took the executable file which is generated in the build folder of the project and executed it on the other linux machine. When I did that I got the following error:
./Project_name: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory
I developed the application using QT 5.3 but the linux machine where I am trying to execute it has libqt4 libraries. Is there any way for this file to be executable using the libqt4 libraries only.The following is my .pro file of the project:
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-08T09:19:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Project_name
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
SOURCES += main.cpp\
mainwindow.cpp \
INCLUDEPATH += /usr/include/python2.7/
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I checked online and found out that we need to make changes in the "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets" so that it works for qt4 libraries. I did that but it did not work. So could you let me know what could be done so that the project which is built using libqt5 can also be executed on machines which have libqt4. Installing libqt5 libraries can be done but I am looking for a way other than that.
Is there any way for this file to be executable using the libqt4 libraries only
Not easily at least... Even if you created symlinks, Qt 4 and Qt 5 are not binary compatible.
If you want to make it self-contained:
bundle the libraries statically.
Use dynamic symbol loading and based on the version you find, you may need to program the code to act differently. But it may be a hell lot of work.
hey make sure libqt5widgets are installed on your system and you are using the correct qmake (version 5x in your case) you can installl them on debian based distro by issuing the command or via Synaptic package manager
sudo apt-get install libqt5widgets5

Installing libusb on windows for use with Qt

I'm trying to install libusb (not libusb-win32) on windows 7. I have to link it with Qt 5.0.1. Here are the problems I'm facing
In the INSTALL file in the extracted libusb folder, it tells me to cd to the current folder then run
./configure
make
makeinstall
But I got the error
'./configure' is not recognized as a valid command.
Googling this problem usually gives the solution as installing libusb-win32. However, I want to avoid that, as of now.
In the libusb library, there were a few MSVC projects, so I built them. That did generated some .lib files. So I proceeded to link them with my Qt project. It recognizes the libusb.h header file but does not link properly. Here is my .pro file
QT += core gui widgets
TARGET = Qt_libusb TEMPLATE = app
SOURCES += main.cpp\
qt_libusb.cpp
HEADERS += qt_libusb.h
FORMS += qt_libusb.ui
LIBS += -LC:\libusb-1.0.18\Win32\Debug\lib\libusb-1.0
INCLUDEPATH += C:/libusb-1.0.18/libusb DEPENDPATH += C:/libusb-1.0.18/libusb
My objective is to link the libusb library with Qt. Please tell me if I haven't 'installed' the library correctly or if I am linking it in a wrong way. thanks
Your project file does not reference the library. You only provide a path where libraries might be found, but there's no reference to the libusb library itself.
What you're missing is something like
LIBS += -llibusb
You also can't have multiple project file statements on the same line. The below is an error:
TARGET = Qt_libusb TEMPLATE = app
It should look like:
TARGET = Qt_libusb
TEMPLATE = app

How do I link to Qwt libraries on Ubuntu?

I have installed the Qwt library on Ubuntu 10.04. The Qwt plotting widgets have appeared in QtCreator but when I try to use any of them I get the error:
"qwt_plot.h" no such file or directory.
Can anyone help?
Edit:
I've solved this by implementing Begemoth's answer as follows:
Open the project file (.pro)
Add the following lines to the bottom of the file:
INCLUDEPATH += /usr/include/qwt-qt4
LIBS += -l qwt-qt4
Ubutu like Debian provides several versions of qwt (for qt4 and qt3), so include files for qwt reside in /usr/include/qwt-qt3 or /usr/include/qwt-qt4 directory, you need to add this directory to the list of the include search path, e.g. with -I gcc flag.
PS: I assume that you have installed the development package for qwt (libqwt5-qt4-dev).