Would anyone know how to include/use the QNX Qt libraries such as QtQnxCar2, QPPS, QPlayer in a Qt project? I think this involves including a package in Qt or may be linking the library in the .pro file, just can't figure out what it is though.
QNX has lot of documentation about the libraries, but nothing about how to actually include and use them in a Qt project.
I am specifically looking for how to use the Qpps namespace in my project. For example, I've linked the qpps library as below in my .pro file:
LIBS += -L/home/me/qnx660/target/qnx6/armle-v7/qtcar/lib/ -lqpps
INCLUDEPATH += /home/me/qnx660/target/qnx6/armle-v7/qtcar
DEPENDPATH += /home/me/qnx660/target/qnx6/armle-v7/qtcar
Here's the code in mainwindow.cpp,
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
using namespace QPps;
Here's the build error:
mainwindow.cpp:5:17: error: 'QPps' is not a namespace-name
mainwindow.cpp:5:21: error: expected namespace-name before ';' token
cc: /home/me/qnx660/host/linux/x86/usr/lib/gcc/arm-unknown-nto-qnx6.6.0eabi/4.7.3/cc1plus error 1
make: *** [mainwindow.o] Error 1
Toolchain:
Qt Creator 3.3.2
Qt 5.2.0
QNX Car 2.1
QNX SDP 6.6
Ubuntu
14.04
EDIT
The question is changed completely! Instead of linking problem, described earlier, now a compiler error is described.
You have to include the header-file first, where the namespace is declared.
e.g:
#include <qpps/changeset.h>
Also, pay attention, that the directory of qpps-include files (headers, .h-files) are defined in the line:
INCLUDEPATH += <Path to your qpps includes >
ORIGINAL ANSWER
If QNX libraries apply to the same rules as other UNIX libraries, you could use them by including this line in your Qt project file (*.pro)
LIBS += -L/Path/to/mylib/ -lmylib
Actually QNX doesn't have to provide any info, how to use their libs in Qt.
The appropriate manual is the QMAKE-manual.
Related
I'm trying to build Qt4 (version 4.8.6) project with Serialport support using CMake (version 2.8.12). Here is the line that adds Qt4 support from my CMake:
find_package (Qt4 COMPONENTS QTCore QTGui REQUIRED)
include("${QT_USE_FILE}")
add_executable(myapp ${SOURCES})
target_link_libraries(myapp ${QT_LIBRARIES})
and getting the following error:
fatal error: QSerialPort: No such file or directory #include <QSerialPort>
I understand that FindQt4.cmake module doesn't have Serialport since it was introduced in Qt5 so i built Serialport library from sources. So the question is how to include the Qt library that is absent in FindQt4.cmake module to build the project via CMake.
The serial port module's code should be a part of your project. Since the project depends on Qt 4, lacking that module, you must bring the code with you. It just a couple of files, adding them to your project is trivial.
I have to use a library under Linux. It's a .so compiled with gcc.
I added on my .pro :
INCLUDEPATH += mypath/include
LIBS += -L/mypath/lib/ -lmyLib
but, i get the following error :
undefined reference to `init_glove(char*, char*)'
I don't understand why i get this message. My library is linked and the header file is founded. I read that it could be a problem between the compiler used for my library, and the one used by Qt, but both seem to be gcc, so...
Any ideas ?
If the problem was the g++/gcc issue, then in your QT project simply do this
extern "C"
{
#include "mylib.h"
}
Actually, Qt was compiling with g++, so I had to change de compiler of my library : switching it from gcc to g++.
Its been 17 days I'm struggling to write a simple program in OpenGL using QT, but all tutorials searched on Google are failed.
I'v compiled my QT 5.0.1 with -opengl desktop using msvc2010 to make desktop opengl default.
I'v read tutorial by Sean Harmer, but it is depended on QT to resolve opengl functions.
According to some people, it is not possible to use glew in QT, as QT's built in libraries prevent glew from including its headers, but according to Sean Harmer HERE , it is possible (but it is not explained there how).
Even using QGLWidget I'm not able to use OpenGL extensions.
Now all I want is to use all OpenGL functions separate and all windowing functions from QT separate, i.e. no interference in OpenGL by QT.
If anybody explain me the procedure with simple triangle example and using any extension, I'l be so thankful..
I'v used glew library in my project and #included glew.h in very start of my program, but when compiled it gives error:
glwidget.obj:-1: error: LNK2001: unresolved external symbol imp__glewGenVertexArrays
My .pro file
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Trial
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp
HEADERS += mainwindow.h \
glwidget.h
FORMS += mainwindow.ui
RESOURCES += \
resources.qrc
win32: LIBS += -L$$PWD/../../../../../OpenGL/glew-1.9.0/lib/ -lglew32s
INCLUDEPATH += $$PWD/../../../../../OpenGL/glew-1.9.0/include
DEPENDPATH += $$PWD/../../../../../OpenGL/glew-1.9.0/include
win32: PRE_TARGETDEPS += $$PWD/../../../../../OpenGL/glew-1.9.0/lib/glew32s.lib
Output by glewInfo :
GLEW version 1.9.0
Reporting capabilities of pixelformat 1
Running on a GeForce GT 540M/PCIe/SSE2 from NVIDIA Corporation
OpenGL version 4.3.0 is supported
void GLWidget::initializeGL()
{
GLenum err = glewInit();
if(err != GLEW_OK)
{
printf("%s",glewGetErrorString(err));
}
glEnable(GL_DEPTH_TEST);
qglClearColor(QColor(Qt::red));
shaderProgram.addShaderFromSourceFile(QGLShader::Vertex, ":/vertexShader.vsh");
shaderProgram.addShaderFromSourceFile(QGLShader::Fragment, ":/fragmentShader.fsh");
shaderProgram.link();
shaderProgram.bind();
const GLubyte *oglVersion = glGetString(GL_VERSION);
printf( "%s\n",oglVersion );
GLfloat vertices[3][3] ={{ -0.5, -0.5, -1 },
{ 0, 0.5, -1},
{ 0.5, -0.5, -1}};
vertexArray.create();
vertexArray.setUsagePattern(QOpenGLBuffer::StaticDraw);
vertexArray.allocate( vertices, 3 * 3 * sizeof( GLfloat ) );
vertexArray.bind();
shaderProgram.setAttributeBuffer( "vVertex", GL_FLOAT, 0, 3 );
shaderProgram.enableAttributeArray( "vVertex" );
GLuint arr[5];
glGenBuffers(5,arr);
}
All problems solved now.
First problem was : QT 5.0.1 does not support opengl by default.
You have to compile it with -opengl desktop.
Here is tutorial on how to compile QT with vs2010.
Or you can download new opengl build from QT.
Second problem in adding glew libraries to project.
If you add glew32s.lib (static) then you have to add "#define GLEW_STATIC" before "#include "
It is advised to use glew32.lib (dynamic).
Third problem was segment fault on some opengl functions even if your GPU supports version 4.3.
GLEW obtains information on the supported extensions from the graphics driver. Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed.
Took 18 days to solve these problems, glad now can start actual programming.
Following code compiles just FINE on MSVC2008 express, qt 4.8.1 and glew version 1.7.0
main.cpp:
#include <GL/glew.h>
#include <QApplication>
#include <QGLWidget>
int main(int argc, char** argv){
glewInit();//<<-- glew function
QApplication app(argc, argv);
QGLWidget widget;
GLuint arr;
glGenVertexArrays(1, &arr);//<--no linker error (added just for testing, most likely won't gen arrays)
widget.show();
return app.exec();
}
gltest.pro:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += . d:/c++/libs/include
LIBS += -L"d:/c++/libs/lib" -lglew32
CONFIG += console
QT += opengl
# Input
SOURCES += main.cpp
I assume that with Qt 5 situation won't be any different.
Feel free to override QGLWidget's paintGL and draw whatever you want using extensions. I don't have a code snippet nearby for that.
Suggestions:
1. Use precompiled binaries.
2. It might make sense to use dynamically-linked version of glew.
3. Notice header inclusion order.
According to some people
People say many things, you don't need to believe all of them.
I would like to share my latest finding about how to make Qt and glew work together on the (currently) latest Windows environments (Qt 5.15.1 + QMake + MSVC 2019 + glew 2.1.0). Hope someone else an avoid spending countless hours on this like me. Here are what I did:
Copy glew32.dll and glew32.lib to somewhere in your project directory. Make sure to the bitness of glew matches with the bitness of the executable you told Qt to build. I did not use the static version of the library because I failed to make that work.
In your .pro (QMake) file, write something like this:
GLEW_INCLUDE_PATH = "$$PWD/ext/glew/include" # put glew headers here
GLEW_LIB_PATH = "$$PWD/ext/glew/x64" # put glew32.dll and glew32.lib here
LIBS += -L$$GLEW_LIB_PATH -lglew32 -lglu32 -lopengl32
DEPENDPATH += .
INCLUDEPATH += $$GLEW_INCLUDE_PATH
The only difference I made compared to the previous answers is that I added -lglu32 and -lopengl32 to the link arguments. It seems that they are mandatory on Windows, othewise MSVC will complain about some link errors with OpenGL API functions.
Additionally, try using QOpenGLWidget instead of QGLWidget. QGLWidget caused some weird OpenGL "Invalid Operation" errors when my program is exiting and trying to destroy OpenGL handles such as buffer and texture handles in destructors. glIntercept showed me that it is because wgl context was destroyed before the handles get released. Switching to QOpenGLWidget solved this problem completely.
Hope you can enjoy using glew with Qt now!
While building a game code in Qt simulator I'm getting the following error:
-1: error: LNK1104: cannot open file 'libEGL.lib'
I have added following code to add library files:
INCLUDEPATH +=
C:\Imagination_Technologies\POWERVR_SDK\OGLES2_WINDOWS_X86EMULATION_2.08.28.0634\Builds\OGLES2\Include\
LIBS +=
-LC:\Imagination_Technologies\POWERVR_SDK\OGLES2_WINDOWS_X86EMULATION_2.08.28.0634\Builds\OGLES2\WindowsX86\Lib\
-llibEGL -llibGLESv2
LIBS += -llibEGL -llibGLESv2
It's been some time since I stopped programming under Windows, but as far as I can remember qmake uses the same mechanism used in Linux on all the supported OS (http://doc.qt.io/qt-5/qmake-project-files.html). Which means you should write:
LIBS += -LC:\Imagination_Technologies\POWERVR_SDK\OGLES2_WINDOWS_X86EMULATION_2.08.28.0634\Builds\OGLES2\WindowsX86\Lib\ -lEGL -lGLESv2
provided the path is correct of course (note that I removed the 'lib').
I am a newby in QT and cannot even get a starting example to work. The problem is that even QtCore is not found. Think something wrong with my path or not the right version is used?
#include <QtCore>
#include <iostream>
#include <QtXml/QXmlSimpleReader>
int main(int argc, char *argv[])
{
QDir xmldir("/xxx/xxx");
QXmlSimpleReader xmlReader;
}
Example of error is:
/Users/frank/xxx-build-desktop/../xxx/main.cpp:1: error: QtCore: No such file or directory.
Checked the path and the path to qmake is /usr/bin/qmake
If I run qmake -v this is printed:
QMake version 2.01a
Using Qt version 4.7.0 in /Library/Frameworks
I am using Mac 10.6.6
Any reply will be appreciated.
Here is the project file:
QT += core gui
QT += xml
QT += webkit
QT += xmlpatterns
TARGET = xxx
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Results from make:
iMac:~/xxx/ qmake -spec macx-g++
iMac:~/xxx/ ls -ltr
total 56
-rw-rw---- 1 frank staff 349 Feb 5 16:06 xxx.pro
-rw-rw---- 1 frank staff 3875 Feb 6 12:56 main.cpp
-rw-rw---- 1 frank staff 7985 Feb 6 12:56 xxx.pro.user
-rw-rw---- 1 frank staff 8974 Feb 6 12:56 Makefile
iMac:~/xxx/ make
g++ -c -pipe -g -gdwarf-2 -Wall -W -DQT_WEBKIT_LIB -DQT_XMLPATTERNS_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.7/mkspecs/macx-g++ -I. -I. -I/usr/include/QtCore -I. -I/usr/include/QtGui -I. -I/usr/include/QtXml -I. -I/usr/include/QtXmlPatterns -I. -I/usr/include/QtWebKit -I/usr/include -I. -F/Library/Frameworks -o main.o main.cpp
main.cpp:1:18: error: QtCore: No such file or directory
main.cpp: In function ‘int main(int, char**)’:
main.cpp:27: error: ‘QDir’ was not declared in this scope
main.cpp:27: error: expected `;' before ‘xmldir’
main.cpp:28: error: ‘xmldir’ was not declared in this scope
main.cpp:28: error: ‘QDir’ is not a class or namespace
main.cpp:28: error: ‘QDir’ is not a class or namespace
main.cpp:28: error: ‘QDir’ is not a class or namespace
main.cpp: At global scope:
main.cpp:25: warning: unused parameter ‘argc’
main.cpp:25: warning: unused parameter ‘argv’
main.cpp:63: warning: unused parameter ‘namespaceURI’
main.cpp:63: warning: unused parameter ‘localName’
main.cpp:63: warning: unused parameter ‘qName’
main.cpp:67: warning: unused parameter ‘namespaceURI’
main.cpp:67: warning: unused parameter ‘localName’
make: *** [main.o] Error 1
iMac:~/xxx/
For most C++ Qt applications you write, it's not immediately obvious how to compile the application by hand. This is complicated by a number of factors:
The header files may be placed in different directories depending on their version
moc, the meta-object compiler, needs to be run
The correct version of the DLLs need to be included
A number of preprocessor defines need to be in place
Given all of the above, it's easiest to use a build system like qmake, which is native to Qt, cmake, or some other build system that is Qt aware.
For people new to Qt, I recommend qmake.
Here's the basic command line usage. Qmake provides integration with both Visual Studio and XCode, but I won't address that here:
Create a directory for your project
Write whatever files you believe you need
Build a project file for qmake by running qmake on your project as follows: qmake -project "CONFIG+=xml". Since you're on mac, you might also want a -macx option, but I've never used it myself. At least in the past, qmake was not smart enough to pick up the XML dependency, so the "CONFIG+=xml" option adds it explicitly.
Create the makefiles from the project file by running qmake again: qmake
Now that you have makefiles, build the application using make, nmake, gmake, or the corresponding version of make for your system.
If everything has been picked up correctly by qmake, you should now be able to build your application by using make.
When you add new files to your project, they will need to be added to your project file (*.pro) and then qmake rerun without any options.
#includes are for header files. QtCore isn't a header, it's a directory that contains headers.
Since you're using QDir, change the first line to this:
#include <QtCore/QDir>
It is rather strange that your /usr/include/* directores don't exist. It seems that there is something wrong with the Qt installation. I don't understand Mac specifics, but from what I've been able to find out, it looks like the -F/Library/Frameworks parameter that make passes to G++ should allow you to use #include <QtCore/QtCore> instead of just #include <QtCore>. In a correct Qt installation on other platforms (Windows, Linux), both forms are equally acceptable though. But judging by the fact that G++ doesn't complain about the #include <QtXml/QXmlSimpleReader> line, the form #include <QtModule/ModuleHeader> works fine in your setup, so it could be used as a workaround, provided that there are no other problems.
Note that I wouldn't recommend to include QtCore in any form, though. It includes a lot of stuff most of which is probably useless to you and it will only increase compilation time and the probability of name conflicts. Include only what you intend to use instead, like #include <QDir> or #include <QtCore/QDir> in your case.
If you are new to Qt, and there's not special build requirement (PPC, 10.4, etc), I would strongly recommend that you download prepackaged Qt SDK of your platform. And use the included IDE, Qt Creator, to start. That will get your feet wet quickly and less painfully.
The variable settings you provided, which seems to be in your makefile, should actually be in a QMake file xxx.pro. You then run qmake, which generates the Makefile from xxx.pro, and then finally can run make. QMake uses variables such as QT and SOURCES, along with its knowledge of Qt and your installation, to produce a correct makefile.
If you do not find QtCore in /usr/include/, then this is an installation issue. In 4.7.0 I heard people having the same problem, so I guess there is a packaging problem for macs in 4.7.0.
Try to get 4.7.1 or build your own out of the sources.