[solved] opening a widget with qml file included
-
wrote on 29 Sept 2011, 13:53 last edited by
@
prima::prima(QWidget *parent) :
QWidget(parent)
{
QDeclarativeView *primaSchermata = new QDeclarativeView(this);
primaSchermata->setSource(QUrl::fromLocalFile("qml/OpenOrario/main.qml"));
primaSchermata->show();QObject *obj = primaSchermata->rootObject(); move(0,0); showMaximized(); QObject::connect(obj, SIGNAL(signal_nuovoClicked()), this, SLOT(nuovo()));
}
void prima::nuovo()
{
seconda s;
}
@@
seconda::seconda(QWidget *parent) :
QWidget(parent)
{
QDeclarativeView *secondaview = new QDeclarativeView(this);
secondaview->setSource(QUrl::fromLocalFile("qml/OpenOrario/seconda.qml"));
secondaview->show();move(0,0); showMaximized();
}
@the second window appears and desappears in a moment...
[edit : typo fixed in title, Eddy]
-
wrote on 29 Sept 2011, 18:08 last edited by
When you enter the prima::nuovo() method, the seconda object gets instantiated on the stack and displayed. As the prima::nuovo() method exits, the seconda object s goes out of scope and the object gets destroyed.
-
wrote on 29 Sept 2011, 18:33 last edited by
0k, so should i use a while, a goto or?
-
wrote on 29 Sept 2011, 18:37 last edited by
Make your "seconda" instance variable a member of your prima class and use new to create your seconda instance. This is pretty basic C++ stuff.
@
class prima ...
{
...
private:
seconda *m_seconda;
}void prima::nuovo()
{
m_seconda = new seconda(this); // create it on the heap, so it doesn't go out of scope
}
@ -
wrote on 29 Sept 2011, 18:39 last edited by
@
void prima::nuovo()
{
seconda s;
s.show();
close();
here:
goto here;
}
@the window stops working...
-
wrote on 29 Sept 2011, 18:42 last edited by
true. thank you!
-
wrote on 29 Sept 2011, 18:44 last edited by
[quote author="spode" date="1317321543"]@
void prima::nuovo()
{
seconda s;
s.show();
close();
here:
goto here;
}
@the window stops working...[/quote]
Oh, that's just so wrong in so many ways... see above.
But let's step through the code...
@
seconda s; // This creates the object
s.show(); // This shows it. It DOES NOT BLOCK AND WAIT FOR THE WIDGET TO CLOSE
close(); // This closes the window immediately.
@Here's an exercise. What do you think the
@
here:
goto here;
@
code does? (Hint... tight, infinite loop)
7/7