January 14, 2012

spode spode
Lab Rat
317 posts

[Solved] [Moved] cannot declare QDeclarativeView into stack

 

why must i declare QDeclarativeView so?

  1. musica1::musica1(QWidget *parent) :
  2.     QWidget(parent)
  3. {
  4.     QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
  5.     this->setAttribute(Qt::WA_LockLandscapeOrientation);
  6.  
  7. ... }

and not so:
  1. musica1::musica1(QWidget *parent) :
  2.     QWidget(parent)
  3. {
  4.     QDeclarativeView view(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
  5.     this->setAttribute(Qt::WA_LockLandscapeOrientation);
  6. ... }

6 replies

January 14, 2012

koahnig koahnig
Gene Splicer
2905 posts

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.

January 14, 2012

spode spode
Lab Rat
317 posts

  1. musica1::musica1(QWidget *parent) :
  2.     QWidget(parent)
  3. {
  4.     view = new QDeclarativeView(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
  5.     this->setAttribute(Qt::WA_LockLandscapeOrientation);
  6.  
  7.     QObject *b = view->rootObject();
  8.     b->setProperty("lunghezza", QApplication::desktop()->geometry().width());
  9.     b->setProperty("altezza", QApplication::desktop()->geometry().height());
  10.  
  11.     connect(b, SIGNAL(signal_musicarequest()), this, SLOT(open_musica2()));
  12.     connect(b, SIGNAL(request_close()), this, SLOT(close()));
  13.  
  14.     view->show();
  15.     this->showFullScreen();
  16. }

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?

January 14, 2012

koahnig koahnig
Gene Splicer
2905 posts

Does it work? If yes, why do you need to change?

January 14, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

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.

January 14, 2012

spode spode
Lab Rat
317 posts

and…if i would like to use view as a global variable, how should i do?

  1. musica1::musica1(QWidget *parent) :
  2.     QWidget(parent)
  3. {
  4.     QDeclarativeView view(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
  5.     this->setAttribute(Qt::WA_LockLandscapeOrientation);
  6.  
  7. ... }

January 15, 2012

Volker Volker
Ant Farmer
5428 posts

Then you have to add a member variable to your class:

header file

  1. class musica1: public QWidget
  2. {
  3. // ...
  4.  
  5. private:
  6.    QDeclarativeView  *view;
  7. };

implementatino

  1. musica1::musica1(QWidget *parent) :
  2.     QWidget(parent)
  3. {
  4.     view = new QDeclarativeView(QUrl::fromLocalFile("qml/Werfer/FliegendeLieder/musica1.qml"), this);
  5.     this->setAttribute(Qt::WA_LockLandscapeOrientation);
  6.     // ...
  7. }
  8.  
  9. void musica1::someMethod()
  10. {
  11.     view->doSomething();
  12. }

That’s pretty basic C++ stuff, so I’ve moved it to the General forum.

 
  ‹‹ not able to view progressbar      [Solved, Moved] More memory needed? ››

You must log in to post a reply. Not a member yet? Register here!