PDA

View Full Version : Strangest error ... like really strange :)



mullwaden
28th August 2008, 16:25
So here is my code:

Control class (it inializes widgets and sets up connects between them)

class Control {


public:

Control();
~Control();

private:

TimeLine *timeLine;
GLWidget *glWidget;
Window *window;
FileHandler *fileHandler;
ContextMenu *contextMenu;
HierarchyWidget *hierarchyWidget;

};

Main class:

int main(int argc, char *argv[])
{
//std::cout << "hej" << std::endl;
QApplication app(argc, argv);

Control control;

return app.exec();
}

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

garry_3peace
28th August 2008, 16:30
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.

mullwaden
28th August 2008, 16:50
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)

wysota
28th August 2008, 16:51
The probable reason is that:


Control control;
This is a declaration of an object "control" of class "Control".


Contol control();
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();".

mullwaden
28th August 2008, 17:06
Ahh I see... still strange ;) Evil C++ strikes again

juannm
29th August 2008, 08:34
yep, that's commented here:

[10.2] Is there any difference between List x; and List x();? (http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2)

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