Results 1 to 20 of 20

Thread: subclassing MainForm class

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

    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
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    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 16:00.
    Regards

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

    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
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    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
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    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
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    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
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    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).

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

    Default Re: subclassing MainForm class

    Thanks. The error is:
    Qt Code:
    1. mymainform.h(4): error C2011: 'myMainForm' : 'class' type redefinition
    To copy to clipboard, switch view to plain text mode 
    I need to obtain his pointer here.
    I don't undertand why for MainForm there aren't problems (I declareed pointer to myMainForm in the same way of pointer to MainForm:
    Qt Code:
    1. //mywidget.h
    2. class MyWidget {
    3. MainForm* w;
    4. myMainForm* myw;
    5. }
    To copy to clipboard, switch view to plain text mode 
    Regards

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

    Default Re: subclassing MainForm class

    Quote Originally Posted by mickey
    mymainform.h(4): error C2011: 'myMainForm' : 'class' type redefinition
    What do you have in 4th line of the mymainform.h class?

    Did you guard all your headers using following code?
    Qt Code:
    1. #ifndef __FILE_NAME_H__
    2. #define __FILE_NAME_H__
    3. ...
    4. #endif // __FILE_NAME_H__
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: subclassing MainForm class

    Now compile successful.
    the line 4 is:
    Qt Code:
    1. class myMainForm : public MainForm
    To copy to clipboard, switch view to plain text mode 
    in mywidget.h I have #include "mymainform.h"
    in mymainform.h I have #include "mywidget.h"
    Is it a cycle!? Is this the cause?
    Thanks
    Regards

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

    Default Re: subclassing MainForm class

    Quote Originally Posted by mickey
    in mywidget.h I have #include "mymainform.h"
    in mymainform.h I have #include "mywidget.h"
    Is it a cycle!?
    Yes, it is. You can avoid it using forward declaration.

  17. The following user says thank you to jacek for this useful post:

    mickey (8th March 2006)

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

    Default Re: subclassing MainForm class

    sorry,
    what does 'forward declarations' mean?
    Regards

  19. #18
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclassing MainForm class

    Quote Originally Posted by mickey
    sorry,
    what does 'forward declarations' mean?
    Ever tried google?

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

    Default Re: subclassing MainForm class

    Hi I tried this and work!
    Qt Code:
    1. #ifndef MYMAINFORM_H
    2. #define MYMAINFORM_H
    3. //#include "mywidget.h"
    4. class MyWidget;
    5.  
    6. class myMainForm : public MainForm
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. myMainForm( QWidget* parent = 0, const char* name = 0, WFlags fl = WType_TopLevel );
    12. ~myMainForm();
    13. MyWidget* myWidget2;
    14. MyWidget* myWidget3;
    15.  
    16. public slots:
    17. void myChangeView(QAction* action);
    18. signals:
    19. void myMainFormUpdate();
    20. };
    21. #endif
    To copy to clipboard, switch view to plain text mode 
    A Question: to toggle include "mywidget.h" I needed to insert #include "mywidget.h" inside mymainform.cpp. Wasn't it the same? Why is better of my previus code (apart avoid cycle problem).
    Thanks
    Regards

  21. #20
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclassing MainForm class

    Quote Originally Posted by mickey
    A Question: to toggle include "mywidget.h" I needed to insert #include "mywidget.h" inside mymainform.cpp. Wasn't it the same? Why is better of my previus code (apart avoid cycle problem).
    Thanks
    You should use forward declarations whenever possible. Use includes only when forward declaration is not suitable.

    Forward declaration is adequate for pointers and references. You have to use includes when compiler needs to know the size of a type. This is the case when you inherit from a class or you have an aggregate object as a class member variable.

    By filling your header files with unnecessary includes only generates extra dependencies and slows compiling down for no purpose at all.

Similar Threads

  1. Replies: 3
    Last Post: 27th December 2008, 20:34
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 08:57
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 08:07
  4. Subclassing qbutton class
    By jingbo in forum Qt Programming
    Replies: 3
    Last Post: 5th October 2006, 22:15
  5. Replies: 2
    Last Post: 4th May 2006, 20: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.