linker errors for QWidget
-
I am getting ~40 or so linker errors for QWidget - examples below.
VS 2017 project is referencing Qt5Guid.lib with directory: C:\Qt\Qt-5.12.1\lib
qt5Guid.lib file is present 9,452 kb
Other QT5 libs are being detected fine (ex: Qt5Cored.lib, Qt5OpenGLd.lib)Error LNK2001 unresolved external symbol "protected: virtual void __thiscall QWidget::actionEvent(class QActionEvent *)" (?actionEvent@QWidget@@MAEXPAVQActionEvent@@@Z) SandBoxGame C:\Projects\SandBoxGame\main.obj 1
Error LNK2001 unresolved external symbol "protected: virtual void __thiscall QWidget::changeEvent(class QEvent *)" (?changeEvent@QWidget@@MAEXPAVQEvent@@@Z) SandBoxGame C:\Projects\SandBoxGame\main.obj 1
Error LNK2001 unresolved external symbol "protected: virtual void __thiscall QWidget::closeEvent(class QCloseEvent *)" (?closeEvent@QWidget@@MAEXPAVQCloseEvent@@@Z) SandBoxGame C:\Projects\SandBoxGame\main.obj 1 -
Hi,
Did you add
QT += widgets
to your .pro file ?
If so, did you then run qmake before building ? -
Didn't use pro file. Background and code if it helps:
needed opengl desktop so did the following:
download source code for 5.12.1
open VS 2017 developer cmd
cd C:\Qt\5.12.1\Src
configure -debug-and-release -opengl desktop
nmake
nmake installmain.cpp
#include <QtWidgets\qapplication.h>
#include "myGlWindow.h"int main(int argc, char* argv[])
{
QApplication application(argc, argv);
MyGlWindow myGlWindow;
myGlWindow.show();return application.exec();
}
myglwindow.h
#ifndef MY_GL_WINDOW
#define MY_GL_WINDOW
#include <QtOpenGL\QGLWidget>
#include <QtCore\qtimer.h>class MyGlWindow : public QGLWidget
{
Q_OBJECTGLuint vertexBufferID; QTimer myTimer;
protected:
void initializedGL();
void paintGL();
private slots:
void myUpdate();
};#endif // !MY_GL_WINDOW
myglwindow.cpp
#include <GL\glew.h>
#include <cassert>
#include "myGlWindow.h"void MyGlWindow::initializedGL()
{GLenum errorCode = glewInit(); assert(errorCode == 0); glGenBuffers(1, &vertexBufferID); glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID); float verts[] = { +0.0f, +0.1f, -0.1f, -0.1f, +0.1f, -0.1f }; glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW); bool keepRunning = true; while (keepRunning) { myUpdate(); } connect(&myTimer, SIGNAL(timeout()), this, SLOT(myUpdate())); myTimer.start(0);
}
void MyGlWindow::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
}void MyGlWindow::myUpdate()
{
} -
There's no need to re-build Qt for that, you can for the backend to use desktop OpenGL on Windows.
If you don't use any .pro file what are you using to manage your project ?
In any case, you have to link against the Qt 5 Widgets library.
-
Then add the Qt Widget module to the list of dependencies of your project.