Results 1 to 6 of 6

Thread: Strangest error ... like really strange :)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Wink Strangest error ... like really strange :)

    So here is my code:

    Control class (it inializes widgets and sets up connects between them)
    Qt Code:
    1. class Control {
    2.  
    3.  
    4. public:
    5.  
    6. Control();
    7. ~Control();
    8.  
    9. private:
    10.  
    11. TimeLine *timeLine;
    12. GLWidget *glWidget;
    13. Window *window;
    14. FileHandler *fileHandler;
    15. ContextMenu *contextMenu;
    16. HierarchyWidget *hierarchyWidget;
    17.  
    18. };
    To copy to clipboard, switch view to plain text mode 

    Main class:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. //std::cout << "hej" << std::endl;
    4. QApplication app(argc, argv);
    5.  
    6. Control control;
    7.  
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    If I in the main class change the line Control control to Control control() the controlclass' constructor will still run without error but... no QT window shows up. So I get a program that continues running but that shows nothing.

    This is very peculiar in my opinion

  2. #2
    Join Date
    Aug 2008
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Strangest error ... like really strange :)

    I am newbie but let me ask first. In the class Control's constructor, what does it do? Of course there is no window show up, because you are not using QWidget. And there is no something to show, somehing code like blabla.show()

    This is my opinion, sorry if I don't fully understand your meaning.

  3. #3
    Join Date
    Aug 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strangest error ... like really strange :)

    I got mainWindow.show() and such in the constructor of controller. Basically what I mean is that if in the main() i write

    Control control; // works
    Control control(); // does not work

    however if I add arguments to the controllers constructor then i can write stuff like

    Control control(45)

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

    Default Re: Strangest error ... like really strange :)

    The probable reason is that:

    Qt Code:
    1. Control control;
    To copy to clipboard, switch view to plain text mode 
    This is a declaration of an object "control" of class "Control".

    Qt Code:
    1. Contol control();
    To copy to clipboard, switch view to plain text mode 
    This is a declaration of function called "control" returning an instance of class "Control".

    Of course withouth calling show() you won't see anything regardless if you use "Control control;" or "Control control();".

  5. #5
    Join Date
    Aug 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strangest error ... like really strange :)

    Ahh I see... still strange Evil C++ strikes again

  6. #6
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    4

    Post Re: Strangest error ... like really strange :)

    yep, that's commented here:

    [10.2] Is there any difference between List x; and List x();?

    You can find a lot of useful C++ tips and caveats in that webpage.

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.