[Solved] [Moved] cannot declare QDeclarativeView into stack
-
why must i declare QDeclarativeView so?
@
musica1::musica1(QWidget *parent) :
QWidget(parent)
{
QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
this->setAttribute(Qt::WA_LockLandscapeOrientation);... }
@
and not so:
@
musica1::musica1(QWidget *parent) :
QWidget(parent)
{
QDeclarativeView view(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
this->setAttribute(Qt::WA_LockLandscapeOrientation);
... }
@ -
You post is just a fragment and does not allow a full explanation.
However, I would assume that you like to use "view" after you have exited the constructor. In the second case it is gone when you leave the contructor. The first is at least still in memory. If you do not handle it somewhere else, you have possibly created a memory leak.
-
@
musica1::musica1(QWidget *parent) :
QWidget(parent)
{
view = new QDeclarativeView(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
this->setAttribute(Qt::WA_LockLandscapeOrientation);QObject *b = view->rootObject(); b->setProperty("lunghezza", QApplication::desktop()->geometry().width()); b->setProperty("altezza", QApplication::desktop()->geometry().height()); connect(b, SIGNAL(signal_musicarequest()), this, SLOT(open_musica2())); connect(b, SIGNAL(request_close()), this, SLOT(close())); view->show(); this->showFullScreen();
}
@and i need to use view on methods. in fact, i declared view as a QDeclarativeView' pointer in the header. so, can i declare QDeclarativeView view in the header and inizialize it in the cpp file as a not-pointer? if not, how to do?
-
Does it work? If yes, why do you need to change?
-
No, you can't. QDeclarativeView is a QObject and thus has no copy constructor or assignment operator.
In addition, QDeclarativeView is a QWidget. There is no need to embed it into a seperate QWidget subclass.
-
and...if i would like to use view as a global variable, how should i do?
@
musica1::musica1(QWidget *parent) :
QWidget(parent)
{
QDeclarativeView view(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
this->setAttribute(Qt::WA_LockLandscapeOrientation);... }
@ -
Then you have to add a member variable to your class:
header file
@
class musica1: public QWidget
{
// ...private:
QDeclarativeView *view;
};
@implementatino
@
musica1::musica1(QWidget *parent) :
QWidget(parent)
{
view = new QDeclarativeView(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
this->setAttribute(Qt::WA_LockLandscapeOrientation);
// ...
}void musica1::someMethod()
{
view->doSomething();
}
@That's pretty basic C++ stuff, so I've moved it to the General forum.