Results 1 to 20 of 20

Thread: subclassing MainForm class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Question subclassing MainForm class

    Hi,
    I'm subclassing MainForm class (create from qtDesigner). I code insert new mymainform.cpp e mymainform.h. and seems ok. But when I create an instance of it in main.cpp, linker get these errors:
    Qt Code:
    1. Editor error LNK2001: unresolved external symbol "public: virtual bool __thiscall myMainForm::qt_emit(int,struct QUObject *)" (?qt_emit@myMainForm@@UAE_NHPAUQUObject@@@Z)
    2. Editor error LNK2001: unresolved external symbol "public: virtual bool __thiscall myMainForm::qt_invoke(int,struct QUObject *)" (?qt_invoke@myMainForm@@UAE_NHPAUQUObject@@@Z)
    3. Editor error LNK2001: unresolved external symbol "public: virtual bool __thiscall myMainForm::qt_property(int,int,class QVariant *)" (?qt_property@myMainForm@@UAE_NHHPAVQVariant@@@Z)
    4. Editor error LNK2001: unresolved external symbol "public: virtual char const * __thiscall myMainForm::className(void)const " (?className@myMainForm@@UBEPBDXZ)
    5. Editor error LNK2001: unresolved external symbol "public: virtual void * __thiscall myMainForm::qt_cast(char const *)" (?qt_cast@myMainForm@@UAEPAXPBD@Z)
    6. Editor error LNK2019: unresolved external symbol "public: static class QMetaObject * __cdecl myMainForm::staticMetaObject(void)" (?staticMetaObject@myMainForm@@SAPAVQMetaObject@@XZ) referenced in function "public: virtual class QMetaObject * __thiscall myMainForm::metaObject(void)const " (?metaObject@myMainForm@@UBEPAVQMetaObject@@XZ)
    7. Editor fatal error LNK1120: 6 unresolved externals
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //mymainform.h
    2. #include "mainform.h"
    3. #include "mywidget.h"
    4. class myMainForm : public MainForm
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. myMainForm( QWidget* parent = 0, const char* name = 0, WFlags fl = WType_TopLevel );
    10. ~myMainForm();
    11. MyWidget top;
    12. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //mymainform.cpp
    2. #include "mymainform.h"
    3. myMainForm::myMainForm( QWidget* parent, const char* name, WFlags fl )
    4. : MainForm( parent, name, fl )
    5. {
    6. }
    7.  
    8. myMainForm::~myMainForm()
    9. {
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //main.cpp
    2. #include "mymainform.h"
    3. ..........
    4. //MainForm w;
    5. myMainForm w;
    6. w.resize(600,500);
    7. a.setMainWidget(&w);
    8. w.show();
    9. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    10. return a.exec();
    To copy to clipboard, switch view to plain text mode 
    What happen?
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: subclassing MainForm class

    Did you rerun qmake after you have added Q_OBJECT to myMainForm class?

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: subclassing MainForm class

    No, but there are still errors (after nmake clean;qmake;nmake)
    Qt Code:
    1. LINK : warning LNK4199: /DELAYLOAD:comdlg32.dll ignored; no imports found from comdlg32.dll
    2. LINK : warning LNK4199: /DELAYLOAD:oleaut32.dll ignored; no imports found from oleaut32.dll
    3. LINK : warning LNK4199: /DELAYLOAD:winmm.dll ignored; no imports found from winmm.dll
    4. LINK : warning LNK4199: /DELAYLOAD:wsock32.dll ignored; no imports found from wsock32.dll
    5. LINK : warning LNK4199: /DELAYLOAD:winspool.dll ignored; no imports found from winspool.dll
    6. main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall myMainForm::~myMainForm(void)" (??1myMainForm@@UAE@XZ) referenced in
    7. function _main
    8. main.obj : error LNK2019: unresolved external symbol "public: __thiscall myMainForm::myMainForm(class QWidget *,char const *,unsigned int)" (??0myMain
    9. Form@@QAE@PAVQWidget@@PBDI@Z) referenced in function _main
    10. Editor.exe : fatal error LNK1120: 2 unresolved externals
    11. NMAKE : fatal error U1077: 'link' : return code '0x460'
    12. Stop.
    To copy to clipboard, switch view to plain text mode 
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: subclassing MainForm class

    Check if you have mymainform.cpp mentioned in SOURCES section of your project file. Add it if it's not there and rerun qmake afterwards.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: subclassing MainForm class

    Thanks you; yes it was .pro

    //mywidget.cpp
    Qt Code:
    1. connect(this, SIGNAL(myUpdate()), w ,SLOT(updateWidgets()) );
    To copy to clipboard, switch view to plain text mode 
    w is MainForm* w; and updateWidget() a SLOT in MainForm class...

    appear a message saying: "no such SLOT" sender and receiver unamed"

    This is the first time I subclassing MainForm created fom QTDesigner. I change only the code You see above and seems works properly! Are there to doother changes?
    Thanks
    Last edited by mickey; 4th March 2006 at 15:00.
    Regards

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: subclassing MainForm class

    I resolve it changing MyWidget declaration to pointer (below coded)
    Qt Code:
    1. class myMainForm : public MainForm
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. myMainForm( QWidget* parent = 0, const char* name = 0, WFlags fl = WType_TopLevel );
    7. ~myMainForm();
    8. void init();
    9. //MyWidget top
    10. MyWidget* top;
    11. };
    To copy to clipboard, switch view to plain text mode 
    But now my problem don't chage. I do it for to do this:
    Qt Code:
    1. myMainForm::myMainForm( QWidget* parent, const char* name, WFlags fl )
    2. : MainForm( parent, name, fl )
    3. {
    4. printf("myMainformt\n");
    5. *top = MyWidget(this, "top shared", this->myWidget1);
    6. this->WidgetStack->addWidget(top);
    7. }
    To copy to clipboard, switch view to plain text mode 
    This two istruction cause some 'debug error' when I launch app....
    The same if I code these two in main.cpp
    Regards

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: subclassing MainForm class

    Nothing hints for this last problem, please?
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: subclassing MainForm class

    Quote Originally Posted by mickey
    *top = MyWidget(this, "top shared", this->myWidget1);
    You can't copy widgets --- try:
    Qt Code:
    1. top = new MyWidget(this, "top shared", this->myWidget1);
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: subclassing MainForm class

    It seems ok;
    I have a problem. In mywidget.cpp constructor I have:
    Qt Code:
    1. connect(this, SIGNAL(myUpdate()), w, SLOT(myUpdateWidgets()) );
    To copy to clipboard, switch view to plain text mode 
    in main.cpp:
    Qt Code:
    1. myMainForm w; a.setMainWidget(&w);....
    To copy to clipboard, switch view to plain text mode 
    When I launch app appear this message:
    Qt Code:
    1. QObject::connect: No such slot MainForm::myUpdateWidgets()
    2. QObject::connect: (sender name: 'myWidget1')
    3. QObject::connect: (receiver name: 'MainForm')
    To copy to clipboard, switch view to plain text mode 

    myUpdateWidgets() is a SLOT of myMainForm! And not MainForm (base class)
    Why doesn't it work? Thanks
    Regards

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: subclassing MainForm class

    How did you declare that slot? Could you also post the .pro file?

  11. #11
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: subclassing MainForm class

    Hi, the error message above is at runtime (in console).
    I saw now the problem is in other place...
    Qt Code:
    1. //myWidget.h
    2. class MyWidget {
    3. MainForm* w;
    To copy to clipboard, switch view to plain text mode 
    }
    When I use in costructor of MyWidget: "connect(this, SIGNAL(myUpdate()), w, SLOT(myUpdateWidgets()) );" w pointer refers to MainForm;
    But if I change in 'myMainForm* w' (in mywidget.h), compiler says me 'class redefinition error....' (error refers to line "class myMainForm {...." in mymainform.h)
    I need a pointer to myMainForm class from MyWidget class (as It was for MainForm..)
    Thanks
    Regards

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: subclassing MainForm class

    Quote Originally Posted by mickey
    But if I change in 'myMainForm* w' (in mywidget.h), compiler says me 'class redefinition error....' (error refers to line "class myMainForm {...." in mymainform.h)
    Could you at least learn to post exact error messages?

    I need a pointer to myMainForm class from MyWidget class (as It was for MainForm..)
    If you need that pointer only to make the connection, then make this connection in a different place (where you have both pointers).

Similar Threads

  1. Replies: 3
    Last Post: 27th December 2008, 19:34
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  4. Subclassing qbutton class
    By jingbo in forum Qt Programming
    Replies: 3
    Last Post: 5th October 2006, 21:15
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.