I'm trying to create a OpenGL widget using Qt 6.4 and VStudio 2022, i have enable the Qt OpenGL widget under the modules, but i still getting a lot of compile errors:
LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QOpenGLWidget::QOpenGLWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QOpenGLWidget##QEAA#PEAVQWidget##V?$QFlags#W4WindowType#Qt#####Z) referenced in function "public: void __cdecl Ui_MainWindowClass::setupUi(class QMainWindow *)" (?setupUi#Ui_MainWindowClass##QEAAXPEAVQMainWindow###Z)
I'm testing in a 'clean' project containing nothing more than a OpenGlWidget added trough QT Designer.
The includes i have added:
#include <QtWidgets>
#include <QtOpenGL>
My project configuration:
I have also tried adding, into Linker -> General -> Additional Library directories:
D:\Qt\6.4.0\msvc2019_64\lib;
And at Linker -> Input -> Additional Dependencies:
Qt6OpenGL.lib
But i continue getting the same errors.
I have installed everything in the Qt Maintenance tool, what i'm missing?
QOpenGLWidget has been moved to Qt OpenGL Widgets module.
You must to link against both Qt6OpenGL.lib and Qt6OpenGLWidget.lib.
https://doc.qt.io/qt-6/opengl-changes-qt6.html#the-qopenglwidgets-class
Which help from Qt Forum, I found that these errors were being caused because I was missing adding the openglwidgets module into the project.
After setting Qt Modules to core;gui;widgets;opengl;openglwidgets it compiled successfully.
It strange that the module openglwidgets is missing in the plugin window of Qt Modules, should be reported as a bug/missing?
Related
I am trying to build OpenCV according to these instructions. After generating with CMake I opened OpenCV.sln in the build folder, switched to Release mode and built ALL_BUILD successfully. But when I try to build the INSTALL option under CMake, I get errors like this:
Error LNK2001 unresolved external symbol "public: virtual struct QMetaObject const * __cdecl cvv::qtutil::Signal::metaObject(void)const "
Error LNK2019 unresolved external symbol "public: void __cdecl cvv::qtutil::ZoomableImage::updateConversionResult(class cv::Mat const &,enum cvv::qtutil::ImageConversionResult)const "
...
I am installing OpenCV 4.2 on Windows 10 with Visual Studio 19. How can I solve this problem?
Here is an image of the error messages in Visual Studio:
Turning my comments into an answer:
The GitHub issue described here references similar errors to those you have posted. While the suggested "solution" seems more like a work-around, it may help resolve the issue. First, try building without the cvv module (an interactive GUI component of OpenCV), by running CMake with the BUILD_opencv_cvv variable set to OFF:
cmake -DBUILD_opencv_cvv=OFF ...
You can also set the variable using the CMake GUI, by clicking the Add Entry button, and defining BUILD_opencv_cvv to OFF.
The GitHub issue further explains that if there are still undefined reference errors after making this change, you can also try setting BUILD_opencv_world to OFF as well.
cmake -DBUILD_opencv_cvv=OFF -DBUILD_opencv_world=OFF ...
This may help get things building successfully, but it should be noted that these disabled modules will be left out of your build.
I want a custom window frame for an app I've made in Qt 5.4 with QML.Before implementing it on my main project, I tried the following on a default application:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//QQmlApplicationEngine engine;
//engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QDeclarativeView view;
viewsetWindowFlags(Qt::FramelessWindowHint
| Qt::WindowSystemMenuHint
| Qt::WindowMinimizeButtonHint
| Qt::Window);
view.setAttribute(Qt::WA_TranslucentBackground);
view.setMaximumHeight(640);
view.setMaximumWidth(350);
view.viewport()->setAutoFillBackground(false);
view.show();
return app.exec();
}
Here is the .pro file:
TEMPLATE = app
QT += qml quick widgets
QT += core gui widgets quick
QT += network
SOURCES += main.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)
The errors:
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QDeclarativeDebuggingEnabler::QDeclarativeDebuggingEnabler(void)" (__imp_??0QDeclarativeDebuggingEnabler##QEAA#XZ) referenced in function "void __cdecl `dynamic initializer for 'qmlEnableDebuggingHelper''(void)" (??__EqmlEnableDebuggingHelper##YAXXZ)
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QDeclarativeView::QDeclarativeView(class QWidget *)" (__imp_??0QDeclarativeView##QEAA#PEAVQWidget###Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QDeclarativeView::~QDeclarativeView(void)" (__imp_??1QDeclarativeView##UEAA#XZ) referenced in function main
I know this is related to my .pro file but not too good in understanding LNk errors, I've tried different things but no progress, till now. How to fix this?
Add to the pro file:
QT += declarative
From the doc:
For the purposes of porting older applications, the QtDeclarative
module is still available in Qt 5 but has been renamed to Qt Quick 1.
Applications that required Qt Quick 1 specific API (e.g.
QDeclarativeView or QDeclarativeItem and the Graphics View
integration) can use this module. Note that new applications should
use the new Qt QML and Qt Quick modules instead.
To use the Qt Quick 1 module, add "declarative" to your qmake .pro
file:
Required header files can be included as follows:
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeItem>
Also:
All classes that were previously in the QtDeclarative module have been
moved into the Qt QML and Qt Quick modules, and their class names have
been changed to reflect their new module locations. The class name
changes are as follows:
... QDeclarativeView -> QQuickView
But:
(The QtDeclarative module is still available to developers as the Qt
Quick 1 module, as discussed below. However, it should not be used for
new applications.)
Just quickly before I start, I have searched SO and Google for a length of time trying to solve this and have been unsuccessful.
I am trying to compile my project, which used to use a certain library for providing GUI functionality based on Windows Forms. Now my company has started to move to Qt, and I decided I would start to convert my small application to support Qt also.
At first it would not compile at all, due to missing headers. Now that is sorted, I am stuck with my final .exe not being able to link due to the following errors.
Creating library Bin\VS_V8\Win32\Debug\Disp.lib and object Bin\VS_V8\Win32\Debug\Disp.exp
QtMainMenu.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QtMainMenu::metaObject(void)const " (?metaObject#QtMainMenu##UBEPBUQMetaObject##XZ)
QtMainMenu.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QtMainMenu::qt_metacast(char const *)" (?qt_metacast#QtMainMenu##UAEPAXPBD#Z)
QtMainMenu.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QtMainMenu::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#QtMainMenu##UAEHW4Call#QMetaObject##HPAPAX#Z)
Bin\VS_V8\Win32\Debug\Disp.exe : fatal error LNK1120: 3 unresolved externals
Our company has a small "Qt Test App" that was written to play around with, which is where I have based my import from. I can compile and link that fine. From what I have gathered, the following properties must be met with Qt files:
Make sure QTDir is included
Add to the UI Files the UIC Compiler
Add to the Resoruce Files the Resource Compiler
Add to the created Header Files the MOC compiler.
I noticed I was missing the MOC Build Tool commands, so I have added them to my UI File's header. However this didnt change the linking problem. I read that I should delete all built files and do a clean to solve it. This didnt work either.
I have checked, and Q_OBJECT is defined in the class.
I am using VS2005 with the Qt Addin. I did not start a new project for Qt however, I am just using the old Visual Studio Solution / VCProj.
Any ideas where to go next?
#Cameron Stubber you need moc object .. You need to modify Custom Build Step.
You can find Custom Build Step in header file (which has Q_OBJECT) Properties by right click. Then type this commands ;
Command Line = $(QTDIR)\bin\moc.exe -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include" -I"$(QTDIR)\mkspecs\$(QMAKESPEC)" finddialog.h -o debug\moc_finddialog.cpp
Description = MOC finddialog.h
Outputs = debug\moc_finddialog.cpp
Additional Dependencies = $(QTDIR)\bin\moc.exe;finddialog.h
But carefull by writing this types you need to change somethings here like $(QTDIR) it is my enviroment variables you need to write full form of where your QT located like D:\qt_5\
and also you need to be carefull finddialog you should write your .h and .cpp files name
And then you need to create a folder by right clicking solution explorer Add\New Filter .. Make folder name as Generated Files
And last step right click Generated Files add\existing item and you will see Debug folder in your solution Project and add moc_"projectName".cpp
Then re-build your solution. Problem will be solved.
Also you should add C/C++ /General/Additional Library Directories
$(QTDIR)\include
$(QTDIR)\include\QtGui
$(QTDIR)\include\QtCore
And Link/General/Additional Library Directories
$(QTDIR)\lib
Link/Input/Additional Dependencies
qtmaind.lib
QtCored4.lib
QtGuid4.lib
But dont forget to change $(QTDIR) to your enviroment variables or location of your qt folder. Like D:\qt_4.7.4
I'm trying to compile a qt project (within Qt Creator 2.7.0 on Qt 5.0.2) and I keep getting linker errors that have to do with the QtSQL library (KioskBridge is the file/class that I am using sql in):
kioskbridge.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlDatabase::QSqlDatabase(void)" (__imp_??0QSqlDatabase##QEAA#XZ) referenced in function "public: __cdecl KioskBridge::KioskBridge(class Html5ApplicationViewer *)" (??0KioskBridge##QEAA#PEAVHtml5ApplicationViewer###Z)
My pro file includes QT += sql, but that doesn't seem to make it link with the appropriate libraries.
Any ideas?
After you modify the .pro file you will need to run qmake (that will re-generate the makefiles with the right dependencies) and only after that you can successfully link your application with the newly added modules.
I am trying to compile a minimal Qt Console application with event loop and a custom class with inline definition of its constructor like https://stackoverflow.com/a/4182144/1619432 and get three cryptic linker errors (using Qt 4.8.1 and MSVC 2010 Express C++):
main.obj:-1: error: LNK2001: Unresolved external symbol ""public: virtual struct QMetaObject const * __thiscall ....
with ::metaObject, ::qt_metacast, ::qt_metacall.
#include "main.moc"
just above the int main(...) is critical. If the file is not found, try cleaning the project / deleting the build directories, running qmake, restarting Qt Creator or even the whole system.
This may have to do with paths in environment variables (maybe set previously by a different project).
Another common reason seems to be a forgotten Q_OBJECT macro in the class declaration, or as above, run qmake after including it.
Good luck!