PDA

View Full Version : add .ui file with custom widget in application



stella1016
18th November 2009, 13:56
Hi,

today I create a self-designed widget, and successfully add it into the designer. I can add it into myDialog.ui in designer.

But then the problem arises, the ui_myDialog.h can not recognize this new widget.

PS: I use " ui.setupUi(this);" in the class to add in the ui.

Who can help me? Thanks.

stella1016
18th November 2009, 14:03
I guess the initialization of the plugin module has some problem. I check it first.

stella1016
18th November 2009, 14:11
No.... There should be no problem.

Currently the compiling error is:


Error 1 error C2061: syntax error : identifier 'myWidget' d:\cvs\module\GeneratedFiles\ui_myDialog.h 263


And this piece of code is only the initialization of my self-designed widget:


myWidget = new myWidget(DialogClass);


Help...

squidge
18th November 2009, 14:12
What do you mean by "can not recognise" ?

stella1016
18th November 2009, 14:25
OK, I found the problem is that I use the same name for both instance and the class name...
Sorry...

Now it has link error.
I am not sure, after adding the widget into the dialog (in designer), the .lib (which is for designer plugin folder) should be added into the project also? I am confused how this widget will work propriately...

stella1016
18th November 2009, 15:47
No body knows???

You can test like this. You put a widget called "WorldTimeClock" in designer in your own dialog *.ui file. During compiling, there is link error.

This is the same problem that I encountered. Hope sb can help. Thanks in advance.

squidge
18th November 2009, 16:17
I don't think it's the "No body knows", but more along the fact of your question is ambiguous.

"there is link error". There's is about 70,000 different answers to that, which would you like to hear? Or you could post something a bit more specific.

stella1016
18th November 2009, 16:51
I don't think it's the "No body knows", but more along the fact of your question is ambiguous.

"there is link error". There's is about 70,000 different answers to that, which would you like to hear? Or you could post something a bit more specific.

OK, then I post the error messages:


Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall WorldTimeClock::WorldTimeClock(class QWidget *)" (__imp_??0WorldTimeClock@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_BodyAdjustmentDialogClass::setupUi(class QDialog *)" (?setupUi@Ui_BodyAdjustmentDialogClass@@QAEXPAVQDi alog@@@Z) bodyadjustmentdialog.obj
Error 2 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall WorldTimeClock::metaObject(void)const " (?metaObject@WorldTimeClock@@UBEPBUQMetaObject@@XZ ) bodyadjustmentdialog.obj
Error 3 error LNK2001: unresolved external symbol "public: virtual void * __thiscall WorldTimeClock::qt_metacast(char const *)" (?qt_metacast@WorldTimeClock@@UAEPAXPBD@Z) bodyadjustmentdialog.obj
Error 4 error LNK2001: unresolved external symbol "public: virtual int __thiscall WorldTimeClock::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@WorldTimeClock@@UAEHW4Call@QMetaObje ct@@HPAPAX@Z) bodyadjustmentdialog.obj
Error 5 error LNK2001: unresolved external symbol "protected: virtual void __thiscall WorldTimeClock::paintEvent(class QPaintEvent *)" (?paintEvent@WorldTimeClock@@MAEXPAVQPaintEvent@@@ Z) bodyadjustmentdialog.obj
Error 6 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall WorldTimeClock::~WorldTimeClock(void)" (__imp_??1WorldTimeClock@@UAE@XZ) referenced in function "public: virtual void * __thiscall WorldTimeClock::`scalar deleting destructor'(unsigned int)" (??_GWorldTimeClock@@UAEPAXI@Z) bodyadjustmentdialog.obj
Error 7 fatal error LNK1120: 6 unresolved externals ..\..\ptf_main\debug\plugins\BodyAdjustmentModule. dl


What I have done, is add one custom widget called "World Timer Clock" in the designer, into my ui file. Then in one of my class bodyadjustementdialog.cpp, I set the .ui for this class.

There comes the link error.

Without the custom widget (world time clock), everything goes fine.

Hope I make myself clear.

squidge
18th November 2009, 19:41
Right, so the code for the actual WorldTickClock class is missing, but the class declaration is there. You need to find and add to your project the actual class code that handles the WorldTimeClock class, and then run QMake to update the MOC dependancies, and then it should work.

stella1016
19th November 2009, 09:17
Right, so the code for the actual WorldTickClock class is missing, but the class declaration is there. You need to find and add to your project the actual class code that handles the WorldTimeClock class, and then run QMake to update the MOC dependancies, and then it should work.

Thanks for your help. I will have a try right away. :)

stella1016
19th November 2009, 09:25
Thanks, it works!!!:p