PDA

View Full Version : mainWindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual s



malfoy1988
7th March 2014, 19:30
Hi,
the other threads didn't help me out.
My code worked so far, but now I tried to connect the Buttons to their function.
Each time I add Q_OBJECT to the mainWindow.h, I get the following errors:

1>mainWindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual struct QMetaObject const * __cdecl mainWindow::metaObject(void)const " (?metaObject@mainWindow@@UEBAPEBUQMetaObject@@XZ)".
1>mainWindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual void * __cdecl mainWindow::qt_metacast(char const *)" (?qt_metacast@mainWindow@@UEAAPEAXPEBD@Z)".
1>mainWindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual int __cdecl mainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@mainWindow@@UEAAHW4Call@QMetaObject@ @HPEAPEAX@Z)".
1>mainWindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: static struct QMetaObject const mainWindow::staticMetaObject" (?staticMetaObject@mainWindow@@2UQMetaObject@@B)".
1>C:\Users\Stefanie\Desktop\Bachelorarbeit\Projekt\v 05\build\Debug\ProgramExec.exe : fatal error LNK1120: 4 nicht aufgelöste Externe

And if I don't use it the connects are not working. (No surprise...)


My code:


main.cpp:
#include <iostream>

// needs to be included before gl.h
#include <GL/glew.h>

#include <QApplication>
#include <QtGui>
#include <QGLFormat>

#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>

#include <QCheckBox>
#include <QComboBox>

#include "gui/openglwindow.h"

#include <QFileDialog>
#include "gui/mainWindow.h"
#include <QMessageBox>


int main( int argc, char *argv[] ) {
// create application and pass arguments
// QT parses args and returns unused args for your usage
QApplication app(argc, argv);

// create main window of our application
// you have to pass the application object
mainWindow *win = new mainWindow();

// report main window to the application
app.setActiveWindow(win);

// set initial size
win->resize(1240,640);

// show the window
win->show();

app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
win->connectAll();

return app.exec();
}


mainWindow.h:
#pragma once

#include <iostream>
#include <QMainWindow.h>

#include <GL/glew.h>

#include <QApplication>
#include <QtGui>
#include <QGLFormat>

#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>

#include <QCheckBox>
#include <QComboBox>

#include "gui/openglwindow.h"
#include "ui_settings.h"

#include <QFileDialog>
#include "ObjLoader/ObjLoader.h"
#include <QMessageBox>

class mainWindow : public QMainWindow
{
Q_OBJECT At this line is the Problem.
public:
mainWindow(void);
OpenGLWindow *renderView; I already tried taking everything out with this class, but it didn't make any difference.
void connectAll(void);

public slots:
void doChooseButton(void);
void doDisplayCombo(int count);
void doLoadButton(void);
void doChooseResolutionBox(int count);
void doSelectButton(void);
void doNormalResolutionBox(bool normal);

private:
Ui::SettingsForm ui_main;
int displayComboCounter;
int resolutionCounter;

protected:

};


mainWindow.cpp:
#include "mainWindow.h"
#include <QMenu>
#include <QMenuBar>



mainWindow::mainWindow(): QMainWindow(){
QWidget *centralWidget = new QWidget(this);

QHBoxLayout *hboxLayout = new QHBoxLayout(centralWidget);

// 2D widget
QGLFormat format;
format.setVersion(4,1);
format.setProfile(QGLFormat::CompatibilityProfile) ;
format.setSampleBuffers(true);
format.setSamples(4);
QGLFormat::setDefaultFormat(format);

renderView = new OpenGLWindow(format);
renderView->setMinimumSize(QSize(400, 400));

// main window
hboxLayout->addWidget(renderView);


QWidget *dialog = new QWidget();

ui_main.setupUi(dialog);
hboxLayout->addWidget(dialog);
setCentralWidget(centralWidget);

//TEST because slots do not work


}


void mainWindow::connectAll(){
connect(ui_main.chooseButton, SIGNAL(clicked()), this, SLOT(doChooseButton()));
connect(ui_main.displayCombo, SIGNAL(activated(int)), this, SLOT(doDisplayCombo(int)));
connect(ui_main.loadButton, SIGNAL(clicked()), this, SLOT(doLoadButton()));
connect(ui_main.chooseResolutionBox, SIGNAL(activated(int)), this, SLOT(doChooseResolutionBox(int)));
connect(ui_main.selectButton, SIGNAL(clicked()), this, SLOT(doSelectButton()));
connect(ui_main.normalResolutionBox, SIGNAL(toggled(bool)), this, SLOT(doNormalResolutionBox(bool)));
}


void mainWindow::doChooseButton(void){

QString selfilter = tr("Model (*.obj)");
try{
QString filename = QFileDialog::getOpenFileName(this, "Choose Object-File", "C:\\", tr("Model(*.obj);;All files (*.*)"),&selfilter);
if(filename.length()!= 0){
QByteArray ba = filename.toLocal8Bit();
const char *charFilename = ba.data();
// TODO ObjLoader* m_Mesh_test = new ObjLoader(tr(charFilename));
if (/* TODO m_Mesh_test->isValid() &&*/ filename.endsWith(".obj")){
if(ui_main.displayCombo->findText(filename) == -1){
ui_main.displayCombo->addItem(filename);
}else{
QMessageBox msgBox;
msgBox.setText("This file is already existent.");
msgBox.exec();
}
}else{
QMessageBox msgBox;
msgBox.setText("This file has the wrong type.");
msgBox.exec();
}
}
}catch(int){

}
}


void mainWindow::doDisplayCombo(int count){
displayComboCounter = count;
}


void mainWindow::doLoadButton(void){

}


void mainWindow::doChooseResolutionBox(int count){
resolutionCounter=count;
}


void mainWindow::doSelectButton(void){

}


void mainWindow::doNormalResolutionBox(bool normal){

}


It would be really nice, if anyone could help me out. I already deleted the build folder a few times. No difference.

ChrisW67
7th March 2014, 21:12
You must rerun qmake and rebuild your project after adding the Q_OBJECT macro.

malfoy1988
7th March 2014, 21:33
I am using cmake and as I told you already, I deleted the build folder so I necessarily had to rerun it. Did not work.... I read that already in previous threads and my Q_OBJECT is already in the code.
Or do I understand anything wrong?
(I had never any problems with my previous projects. I also used cmake and Q_OBJECT at those)

Alundra
7th March 2014, 22:01
I don't see problem on the first view of the code, maybe you forgot something in the cmake script ?
Only one line is enough : set(CMAKE_AUTOMOC TRUE).

malfoy1988
7th March 2014, 22:32
Hi,
I was missing that line, but it still doesn't work. Thanks anyways.
Now I am getting these errors:

2>ProgramExec_automoc.obj : error LNK2005: "public: virtual struct QMetaObject const * __cdecl OpenGLWindow::metaObject(void)const " (?metaObject@OpenGLWindow@@UEBAPEBUQMetaObject@@XZ ) ist bereits in moc_openglwindow.obj definiert.
2>ProgramExec_automoc.obj : error LNK2005: "public: virtual void * __cdecl OpenGLWindow::qt_metacast(char const *)" (?qt_metacast@OpenGLWindow@@UEAAPEAXPEBD@Z) ist bereits in moc_openglwindow.obj definiert.
2>ProgramExec_automoc.obj : error LNK2005: "public: virtual int __cdecl OpenGLWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@OpenGLWindow@@UEAAHW4Call@QMetaObjec t@@HPEAPEAX@Z) ist bereits in moc_openglwindow.obj definiert.
2>ProgramExec_automoc.obj : error LNK2005: "private: static void __cdecl OpenGLWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@OpenGLWindow@@CAXPEAVQObject@ @W4Call@QMetaObject@@HPEAPEAX@Z) ist bereits in moc_openglwindow.obj definiert.
2>ProgramExec_automoc.obj : error LNK2005: "public: static struct QMetaObject const OpenGLWindow::staticMetaObject" (?staticMetaObject@OpenGLWindow@@2UQMetaObject@@B) ist bereits in moc_openglwindow.obj definiert.
2>C:\Users\Stefanie\Desktop\Bachelorarbeit\Projekt\v 05\build\Debug\ProgramExec.exe : fatal error LNK1169: Mindestens ein mehrfach definiertes Symbol gefunden.

At least something changed. XD


My cmakelists:
SET(CMAKE_PREFIX_PATH
"C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x64"
)

# project name
PROJECT(FrameworkName)

# cmake version
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)

# find and setup Qt5 for this project
FIND_PACKAGE(Qt5Core REQUIRED)
FIND_PACKAGE(Qt5Widgets REQUIRED)
FIND_PACKAGE(OPENGL REQUIRED)


INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${FrameworkName_SOURCE_DIR}
${FrameworkName_SOURCE_DIR}/ext
${FrameworkName_BINARY_DIR}
${OPENGL_INCLUDE_DIR}
)

SET( LIBRARIES
${OPENGL_LIBRARIES}
${QT_LIBRARIES}
)

# .cxx sources
SET(FrameworkName_SRCS
main.cpp
ext/GL/glew.c
gui/openglwindow.cpp
gui/mainWindow.cpp
ObjLoader/ObjLoader.cpp
shader/simpleshader.frag
shader/simpleshader.vert
)

# files which need to be moc'd by Qt (header)
SET(FrameworkName_MOC_HDRS
gui/openglwindow.h
)

# .h sources
SET(FrameworkName_HDRS
${FrameworkName_MOC_HDRS}
ext/GL/glew.h
ObjLoader/ObjLoader.h
gui/mainWindow.h

)


SET(FrameworkName_UI
gui/settings.ui
)

SET(
CMAKE_AUTOMOC TRUE
)


# build ui_XXX files from the XML-style .ui files
QT5_WRAP_UI(FrameworkName_HDRS ${FrameworkName_UI})

# this moc's the above variable and appends to the cxx sources
QT5_WRAP_CPP(FrameworkName_SRCS ${FrameworkName_MOC_HDRS})


IF(UNIX)
ADD_EXECUTABLE(ProgramExec ${FrameworkName_SRCS} ${FrameworkName_HDRS})
ELSEIF(APPLE)
ADD_EXECUTABLE(ProgramExec MACOSX_BUNDLE ${FrameworkName_SRCS} ${FrameworkName_HDRS})
ELSEIF(WIN32)
ADD_EXECUTABLE(ProgramExec ${FrameworkName_SRCS} ${FrameworkName_HDRS})
ENDIF()

QT5_USE_MODULES(ProgramExec Widgets OpenGL)

set_property(
TARGET ProgramExec
PROPERTY COMPILE_DEFINITIONS GLEW_STATIC
)

TARGET_LINK_LIBRARIES(ProgramExec ${LIBRARIES})

anda_skoa
8th March 2014, 09:15
I think the automoc is now clashing with your manual moc rule.
Try removing


QT5_WRAP_CPP(FrameworkName_SRCS ${FrameworkName_MOC_HDRS})


Cheers,
_

malfoy1988
8th March 2014, 10:27
Thanks a lot. It works. :)
You really saved me. ;) I am not that good with cmakelists.