PDA

View Full Version : link error LNK2001 with Q_OBJECT



mioan
16th May 2009, 19:20
Hi, have a windows screensaver that I am converting to use QT.
I made it use QSettings for the ini settings.

I want to use QTimer and it sais I must include Q_OBJECT in the class definition for the slots to work with the timer.
When I put Q_OBJECT, I get this link error:
error LNK2001: unresolved external symbol "public: virtual struct QMetaObject


Which lib do I need to include?

I am developing the windows screensaver with visual studio 2005
Here is my linker settings:

/OUT:"c:\windows\SYSTEM32\STARMSG.SCR" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"c:\windows\temp\STARMSG.SCR.intermediate.manifest" /NODEFAULTLIB:"LIBCD" /DEF:".\StarMsg.def" /PDB:".\..\Release/STARMSG.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT Qt3Support4.lib QtGui4.lib QtCore4.lib winmm.lib scrnsave.lib WSOCK32.lib Comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

Thanks for any ideas.
Mike

lyuts
17th May 2009, 10:00
Show us this code.

While code is missing, the first guess is that you should run qmake after adding Q_OBJECT.

auba
17th May 2009, 11:04
I guess this is a VStudio project... ? Has the (generated) moc_-file been added to the source files?

mioan
17th May 2009, 23:52
Dear lyuts and auba,
thank you for your replies.

yes, I have written this screensaver in visual studio and I want to gradually transfer it to QT.

1) I could not find any moc_*.* files that I could include in the source.
(Except of lost of files in the qt folders)
Which one should I include in the source files?

2) The source is this one:


////////////////////////////////////////////////////
// TmioanScreenSaveAppl.h

#pragma once

#include "TmioanApplication.h"
#include <QTimer.h>
#include <QObject.h>


class TmioanScreenSaveAppl: public TmioanApplication, QObject
{
// Q_OBJECT
// With Q_OBJECT the linker gives an error
// Without Q_OBJECT the timer does not work

// All classes that contain signals or slots must mention Q_OBJECT at the top of their declaration.
// They must also derive (directly or indirectly) from QObject.


private:
QTimer *timer;

public:
TmioanScreenSaveAppl(char *aCompanyName, char *aProductName);
virtual ~TmioanScreenSaveAppl(void);

void Startup(void);
void Shutdown(void);

public slots:
void Advance(void);

void ConfigDialog(void);
};


////////////////////////////////////////////////////
// TmioanScreenSaveAppl.cpp

#include "TmioanScreenSaveAppl.h"
#include "LogFileClass.h"


TmioanScreenSaveAppl::TmioanScreenSaveAppl(char *aCompanyName, char *aProductName)
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(Advance()));
}


TmioanScreenSaveAppl::~TmioanScreenSaveAppl(void)
{
delete timer;
}


void TmioanScreenSaveAppl::Startup(void)
{
timer->start(50); // millisecond
LogFile.add(lm_INFOLN,"TmioanScreenSaveAppl","Startup()");
}


void TmioanScreenSaveAppl::Shutdown(void)
{
timer->stop();
}

void TmioanScreenSaveAppl::Advance(void)
{
LogFile.add(lm_INFOLN,"TmioanScreenSaveAppl","Advance()");
}




void TmioanScreenSaveAppl::ConfigDialog(void)
{

}