Error: undefined reference to QQuickRectangle::QQuickRectangle(QQuickItem*) - qt

I want to use Qt Quick 2 directly from C++ without those qml/javascript stuffs that could slows down the app, but i got compilation error when using QQuickRectangle (Rectangle when used from qml).
In .pro file i have: QT += quick quick-private core-private gui-private declarative-private qml-private
and in .cpp file - #include <private/qquickrectangle_p.h>
I compiled the Qt 5.5 from sources and the command nm -D /usr/local/Qt-5.5.0/lib/libQt5Quick.so.5 | grep "Rectangle"
doesn't print anything related to QQuickRectangle, so it looks that it is not included in the shared library, but i don't know why, because the qquickrectangle.cpp exists in qt sources, so it should be included in the shared library after compilation.

Related

Compile error in Qt/C++

I am trying to compile an example from a library.
I have Qt installed but I think I have to link it and I don't know how.
This is the error:
g++ face_recognition.cpp -o test
In file included from face_recognition.cpp:29:0:
/usr/local/include/openbr/openbr_plugin.h:22:23: fatal error: QDataStream: No such file or directory
#include <QDataStream>
^
compilation terminated.
You can't compile a Qt application directly with g++ because the application must first go through Qt's moc compiler.
If you want to build a Qt application from the cmd-line, make sure you define an appropriate .pro file that specifies the Qt modules and other 3rd party headers/libraries you want might to use. For instance:
QT += core widgets
SOURCES += \
main.cpp
Then invoke qmake on the command line in the same directory as the .pro file to build the appropriate Makefiles, and finally execute make to build the app.

Qt Cannot open include file: 'QPrinter'

I am new to Qt. Downloaded source code for a Qt application of SourceForge, and tried to build and run it. After working through a few similar problems by adding QT += statements to .pro files, I am stuck on this one:
On attempting to build in Qt Creator, I get errors saying
error: C1083: Cannot open include file: 'QPrinter': No such file or directory
I tried adding QT += printsupport to the .pro file, cleaning, and rebuilding, but that gives this error
Error: dependent '..\..\..\..\..\..\..\..\..\..\..\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport\qtprintsupportglobal.h' does not exist."
When I go to C:\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport, qtprintsupportglobal.h IS THERE!
You have to add QPrinter Support to your project's .pro file:
QT += printsupport
In my case the solution was to
Delete the shadow build directory and build again
after adding printsupport, as #KubaOber suggests in the comments.
Easy mistake to make: After you edit your .pro
QT += printsupport
You have to SAVE the file before your .h will be aware of it.
Because QMake will eventually be dropped in favor of CMake, here's the solution for CMake users:
Pass PrintSupport to the find_package call, to the right side of COMPONENTS, like in this example:
find_package(Qt5 ${QT5_MIN_VERSION} REQUIRED COMPONENTS Core Gui Qml QuickControls2 PrintSupport)

Qt: mingw compiled library does only work with both library.so and library.lib file present

I compiled a library using the MinGW toolchain provided with Qt 5.0.2 on Windows. As a result I received a library.so file. First I failed using the library in a Qt application, but now I found out that everything works fine when I make a copy of the liblibrary.so file and call it liblibrary.dll or liblibrary.lib (which is the only file ending supported by the add library wizard in QtCreator).
Now I wonder if this is normal or if I should change something in order not to have both files (which are exact copies). Leaving one away makes the application crash during start up. I added the library as follows to my Qt pro file:
LIBS += -L"../path/to/library" -llibrary
INCLUDEPATH += $$quote(../path/to/library)
EDIT: I compiled the library using the MinGW of Qt, not as Qt project but using mingw32-make and the provided Makefile. As a result I get the liblibrary.so.
EDIT: It seems to work also when renaming the copy to liblibrary.dll instead of .lib. But still, I need two files to make the application work -- the .so and the .dll.
Chris
That's weird, I think you should get a *.a and *.dll files when building a shared lib with MinGW on Windows, as said in the documentation:
In windows, MinGW will output .a and .dll, MSVC2010 will ouput .lib and .dll. In linux, MinGW will output .so, .so.1, .so.1.0 and .so.1.0.0 – .lib, .a and .so are import libraries.
You definitely shouldn't rename your file!
Be careful to:
not to include the "lib" prefix after "-l" in your project file.
put everything after after "-l" in lower case as you're on Windows
not adding any extension to your library name after "-l"
add and reference the .h file used in your library
A real example using QtWebsocket lib:
INCLUDEPATH += "$${PWD}/include/"
LIBS += -L"$${PWD}/libs/" -lqtwebsocket
...
HEADERS += ... \
$${PWD}/include/QWsSocket.h \
...
In my include/ folder, I have the following file:
QWsSocket.h (taken from original project - required)
In my libs/ folder, I have the following file:
libQtWebsocket.a
QtWebsocket.dll
Edit: I struggled with this too initially. Have you tried to build your lib as a static lib instead (CONFIG += staticlib in your library project)? This might help you getting you *.pro file right before switching to using the shared library.
Edit 2: Ok, the fact that you get a *.so file is still a bit odd. In this question
the user has the same issue as you and keep both files, which is just a workaround. According to a later answer it seems that you need to modify your makefile to generate a file with the proper extension. Maybe this will help: http://www.mingw.org/wiki/sampleDLL

Qt OpenGL compile Static

I wrote a small app with qt and opengl (code) and I want to compile it static now.
So i downloaded Qt library and compile it static using this guide.
I added a line CONFIG += static to the pro file cd to the project location and hit:
make clean
qmake -config release
make
but I am getting several undefined references like:
qpixmapdata_gl.cpp:-1: error: undefined reference to `_imp___Z14qt_defaultDpiYv'
What I am doing wrong? Do I need to add the libs to the pro file? How do I do this and more important what libs should I use?
I tried something like this with no result:
LIBS += C:\Qt\4.7.3\bin\QtOpenGL4.dll
I see that symbol is defined in qfont.cpp, so it should be there. I would try to add:
QT += gui
in your .pro file. And I suppose you need:
QT += core
also.
EDIT: Try also to check that the symbol is included in the libQtGui.lib and the line used to compile.
Are you using the same compiler also? The mangling reported seems that of gcc. Did you compile Qt libraries with mingw or nmake?

undefined reference linker error with signals and slots

Using Qt Creator, I am creating a class with custom slots in Qt:
class CustomEdit : public QTextEdit
{
Q_OBJECT
public:
CustomEdit(QWidget* parent);
public slots:
void onTextChanged ();
};
However, I'm getting this linker error:
undefined reference to 'vtable for CustomEdit'
The documentation says:
if you get compiler errors along the lines of "undefined reference to vtable for LcdNumber", you have probably forgotten to run the moc or to include the moc output in the link command.
... but it is not obvious what that means.
Is there something I need to add to my class, or to the .pro file?
EDIT -- Here is my .pro file:
QT += network \
script \
webkit \
xml
TARGET = MyApp
TEMPLATE = app
SOURCES += main.cpp \
MainWindow.cpp \
CustomEdit.cpp
HEADERS += MainWindow.h \
CustomEdit.h
FORMS += mainwindow.ui
EDIT:
This question deals with the same problems, but the answers don't make it clear how I can fix this issue in Qt Creator. Do I need to explicitly add the moc-generated .cpp file to my list of files to be linked? That seems like a pain.
Qt creator is an IDE which is used to create your Qt projects. That's all. But qmake allows you to buid the project. From qmake manual,
qmake automates the generation of Makefiles so that only a few lines of information are needed to create each Makefile. qmake generates a Makefile based on the information in a project file. qmake contains additional features to support development with Qt, automatically including build rules for moc and uic.
You don have to include your moc files separately, but you have to run qmake which contains all the information about the required moc files. Take a look at the generated Makefile.debug or Makefile.release after qmake and you can find all the moc files will be included for you.
Now to run qmake in Qt creator, just go to Build->RebuildAll which will run the qmake and all the (moc) files will be generated and linked (in Makefile.debug) as well.
Hopefully this will elimate your undefined reference.

Resources