Try putting the slot after constructor is defined.
Might help
Try putting the slot after constructor is defined.
Might help
You seem to have forgotten to inclde the moc file generated. Suppose the file name is MyWidget.cpp. after the main function, #include "MyWidget.moc"
We can't solve problems by using the same kind of thinking we used when we created them
I dont think thats the case...
and I even dont think this is a simple example...
I tried the code too, (VC++ 6.0 )but it is giving the following errors :
when i remove the slot and Q_OBJECT from the code, it works fine... thers something wrong with the slot function .... I am really confused too--------------------Configuration: test - Win32 Release--------------------
Running MOC on release\test.moc
Compiling...
dump.cpp
test.cpp
Generating Code...
Linking...
test.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall MyWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyWidget@@UAEHW4Call@QMetaObject@@HP APAX@Z)
test.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyWidget::qt_metacast(char const *)" (?qt_metacast@MyWidget@@UAEPAXPBD@Z)
test.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyWidget::metaObject(void)const " (?metaObject@MyWidget@@UBEPBUQMetaObject@@XZ)
test.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const MyWidget::staticMetaObject" (?staticMetaObject@MyWidget@@2UQMetaObject@@B)
release/test.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
test.exe - 5 error(s), 0 warning(s)![]()
![]()
Last edited by jacek; 16th January 2007 at 11:22. Reason: changed [code] to [quote]
Move you class definition into a header and use qmake.
Q_OBJECT in a class defintion inside a source file does not work.
aamer4yu (16th January 2007)
hmm...it works !!
Indeed a simple problem !!![]()
I think you shouldn't think too much, and just try out the solution mentioned
Qt Code:
#include <QApplication> #include <QFont> #include <QPushButton> #include <QWidget> #include <QCalendarWidget> #include <QVBoxLayout> #include <iostream> { Q_OBJECT public: public slots: } ; { std::cout << theDate.toString( "ddd MMMM d yyyy" ).toStdString() << std::endl ; } { quit->setGeometry ( 62, 40, 75, 30 ) ; connect ( quit, SIGNAL( clicked() ), qApp, SLOT(quit()) ) ; connect ( dateEdit, SIGNAL( clicked(const QDate&) ), this, SLOT(calClicked(const QDate&)) ) ; layout->addWidget(dateEdit); layout->addWidget(quit); setLayout(layout); } int main(int argc, char* argv[] ) { MyWidget widget ; widget.show() ; return app.exec() ; } #include "main.moc"To copy to clipboard, switch view to plain text mode
Try this code out It should compile
We can't solve problems by using the same kind of thinking we used when we created them
ok I am not thinking much now..
can u tell more ? how does moc work ?
if main.moc was not included, main_moc.cpp might have been generated ? hope I am right... are there any other files generated ??
how do one choose to what to include? ?
As you can moc can work on a source and on a header file. For a beginner it's imo better to just use the header-file approach.
moc on src file creates a <filename>.moc which has to be included in <filename>.cpp
moc on header file creates moc_<filename>.cpp which is automagically added to the sourcefile-list by qmake.
Be aware that cmake & automake use a different naming sheme (and you have to include moc src and moc header - it's not done by the buildsystem there)
Thanks. That did it .![]()
Bookmarks