Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] [Moved] cannot declare QDeclarativeView into stack
Forum Updated to NodeBB v4.3 + New Features

[Solved] [Moved] cannot declare QDeclarativeView into stack

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    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);
    ... }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on last edited by
        #3

        @
        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?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

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

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              spode
              wrote on last edited by
              #6

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

              ... }
              @

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                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.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved