Results 1 to 7 of 7

Thread: #include class

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

    Default #include class

    Hi, I've done this thing; I wonder if could arise a problem...can I avoid _myw with a simple parent() ??? thanks
    Qt Code:
    1. #include "mymainform.h"
    2. myLightDialog::myLightDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
    3. :lightDialog (parent, name, modal, fl) {
    4. _myw = (myMainForm*) parent;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include <myLightDialog.h>
    2. myMainForm::myMainForm( QWidget* parent, const char* name, WFlags fl )
    3. : MainForm( parent, name, fl )
    4. {
    5. lightd = new myLightDialog(this);
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: #include class

    I don't understand your question exactly, but you're probably worried about the recursive inclusion. Instead of including it in mylightdialog.h, you can predeclare the myMainForm class and then really include it in the .cpp/.cc file. So it would become:

    Qt Code:
    1. class myMainForm;
    2.  
    3. myLightDialog::myLightDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
    4. :lightDialog (parent, name, modal, fl) {
    5. _myw = (myMainForm*) parent;
    To copy to clipboard, switch view to plain text mode 
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    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: #include class

    Quote Originally Posted by mickey
    Hi, I've done this thing; I wonder if could arise a problem...can I avoid _myw with a simple parent()
    No, because parent() is of type QWidget* and _myw is of type myMainForm*. You can use parent() but you'll have to cast it to myMainForm* each time you want to use any of myMainForm methods. But you may define such a method in your class:

    Qt Code:
    1. inline myMainForm* myLightDialog::formParent(){ return dynamic_cast<myMainForm*>(parent()); }
    To copy to clipboard, switch view to plain text mode 

    and use formParent() instead of parent().

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

    Default Re: #include class

    thanks, but I worried for recursive inclusion; I already inserted "class myMainForm" in myLightDialog Class (.h); that's the .cpp; Don't I have to insert "#include <mymainform.h> there" (in the .cpp)?
    Regards

  5. #5
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: #include class

    Yes, include mymainform.h into mylightdialog.cpp. In mydialog.h you only needed the name. In the .cpp you need the actual class (probably).
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

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

    Default Re: #include class

    Quote Originally Posted by Michiel
    Yes, include mymainform.h into mylightdialog.cpp. In mydialog.h you only needed the name. In the .cpp you need the actual class (probably).
    sorry but #include "mymainfrom.h" in .cpp seems necessary....don't compile with only class mymainform...
    these are the errors:
    Qt Code:
    1. myLightDialog.cpp(27): error C2027: use of undefined type 'myMainForm'
    2. myLightDialog.cpp(27): error C2227: left of '->isEnabled' must point to class/struct/union
    3. myLightDialog.cpp(27): error C2227: left of '->tab1' must point to class/struct/union
    4. myLightDialog.cpp(28): error C2027: use of undefined type 'myMainForm'
    To copy to clipboard, switch view to plain text mode 
    Regards

  7. #7
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: #include class

    Yes, it is necessary, like I said.

    In the .h file you only use 'class myMainForm'. In the .cpp file you use '#include "mymainform.h"'.

    This way you won't get compiler errors, and you won't have recursive inclusion (which would only have happened with '#include ...' in the .h file).
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Similar Threads

  1. QApplication: no such file or directory
    By jochen_r in forum Newbie
    Replies: 13
    Last Post: 15th November 2008, 22:46
  2. Replies: 7
    Last Post: 2nd June 2006, 13:48
  3. Replies: 2
    Last Post: 4th May 2006, 20:17
  4. use button from another Window
    By raphaelf in forum Qt Programming
    Replies: 11
    Last Post: 2nd March 2006, 21:31
  5. Problems with Q_OBJECT and subclassing
    By renaissanz in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2006, 23:18

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.