I moved the class definition to a seperate header file , and added Q_OBJECT macro. here is how the code looks like now.
And I still get the unresolved symbols
error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SMainWindow::metaObject(void)const " (?metaObject@SMainWindow@@UBEPBUQMetaObject@@XZ)
error LNK2001: unresolved external symbol "public: virtual void * __thiscall SMainWindow::qt_metacast(char const *)" (?qt_metacast@SMainWindow@@UAEPAXPBD@Z)
error LNK2001
: unresolved external symbol
"public: virtual int __thiscall SMainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SMainWindow@@UAEHW4Call@
QMetaObject@@HPAPAX@Z
)fatal error LNK1120: 3 unresolved externals
error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SMainWindow::metaObject(void)const " (?metaObject@SMainWindow@@UBEPBUQMetaObject@@XZ)
error LNK2001: unresolved external symbol "public: virtual void * __thiscall SMainWindow::qt_metacast(char const *)" (?qt_metacast@SMainWindow@@UAEPAXPBD@Z)
error LNK2001: unresolved external symbol "public: virtual int __thiscall SMainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SMainWindow@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
fatal error LNK1120: 3 unresolved externals
To copy to clipboard, switch view to plain text mode
smainwindow.h
#pragma once
#include "QApplication.h"
#include "QMainWindow.h"
{
Q_OBJECT
private slots:
void slotNewGraph();
};
#pragma once
#include "QApplication.h"
#include "QMainWindow.h"
class SMainWindow:public QMainWindow
{
Q_OBJECT
private slots:
void slotNewGraph();
};
To copy to clipboard, switch view to plain text mode
smainwindow.cpp
#include "smainwindow.h"
void SMainWindow::slotNewGraph()
{
printf ("new Graph\n");
}
#include "smainwindow.h"
void SMainWindow::slotNewGraph()
{
printf ("new Graph\n");
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "QApplication.h"
#include "frmmain.h"
#include "smainwindow.h"
int _tmain(int argc, char** argv)
{
Ui::MainWindow ui;
SMainWindow* mainForm=new SMainWindow;
ui.setupUi(mainForm);
QAction* actionNew
= mainForm
->findChild<QAction
*>
("actionNew");
QObject::connect(actionNew,
SIGNAL(activated
()), mainForm,
SLOT(slotNewGraph
()));
mainForm->show();
return app.exec();
return 0;
}
#include "QApplication.h"
#include "frmmain.h"
#include "smainwindow.h"
int _tmain(int argc, char** argv)
{
QApplication app(argc,argv);
Ui::MainWindow ui;
SMainWindow* mainForm=new SMainWindow;
ui.setupUi(mainForm);
QAction* actionNew = mainForm->findChild<QAction*>("actionNew");
QObject::connect(actionNew, SIGNAL(activated()), mainForm, SLOT(slotNewGraph()));
mainForm->show();
return app.exec();
return 0;
}
To copy to clipboard, switch view to plain text mode
P.S frmmain.h is a qt designer generated header.
Bookmarks