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] Swapping QDeclarativeView QML Sources
QtWS25 Last Chance

[Solved] Swapping QDeclarativeView QML Sources

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.9k Views
  • 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.
  • T Offline
    T Offline
    Tjsail33
    wrote on last edited by
    #1

    First question here, so bear with me.

    I have been trying to create a view on a QMainWindow using a QDeclarativeView as the canvas, but whenever I try to switch the source of the QDeclarativeView my program segfaults and I frankly have no idea why, or how to fix it.

    Here is my swapView() function.

    @void MainWindow::swapView(int view)
    {
     switch (view)
     {
        case 0:
            cout << "Switching to Slideshow..." << endl;
            this->setSource("Slideshow.qml");
            break;
        case 1:
            cout << "Switching to Main Canvas..." << endl;
            this->setSource("Test.qml");
            cout << "Successfully switched to Main Canvas!" << endl;
            break;
     }
    }@
    

    Here is the setSource() method that it is calling:

    @void MainWindow::setSource(QString fileName)
    {
        this->ui->declarativeView->setSource(QUrl::fromLocalFile&#40;"Test.qml"&#41;&#41;;
    }@
    

    I tried replacing the code above with the code below, and it gets rid of the segfault, but each window opens in a separate window instead of just replacing the view on the QDeclarativeView.

    @void MainWindow::setSource(QString fileName)
    {
        QDeclarativeView *view = new QDeclarativeView;
        view->setSource(QUrl::fromLocalFile&#40;fileName&#41;&#41;;
        ui->declarativeView = view;
        ui->declarativeView->show();
    }@
    

    If anyone has any input on what I'm doing wrong (I'm sure it's something stupid), please let me know...

    Thanks.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tjsail33
      wrote on last edited by
      #2

      nobody has any ideas on how I can fix this problem...?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        You could use a QStackedWidget and put two QDeclarativeView widgets on it. Then you could easily switch between them.

        Edit to add:

        Also, please be patient when posting and try to wait at least a day or two before bumping your topic. We're all volunteers here, and if someone has answers, they'll get to you as soon as they can.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

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

          Does that crash also happen in case you have just "hello world 1" and "hello world 2" QML files? Maybe there are some issues on destroying the previous QML stuff and/or its C++ backend (if any?). Where does the crash happen exactly? The debugger should throw you at the correct line.

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tjsail33
            wrote on last edited by
            #5

            First, thanks for the responses. When I have time to work on the program in an hour or two I'll try the QStackedWidget suggestion. So thanks for that mlong. Volker, I'm not sure if this is what youre looking for but as a fairly big QT/C++ newbie I'm not exactly sure what all of the gdb printout means. So, I ran my program in gdb, and here is the printout. I hope this helps diagnose the error...

            @(gdb) run
            Starting program: **********************************
            [Thread debugging using libthread_db enabled]

            (Axiom:17606): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

            (Axiom:17606): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

            (Axiom:17606): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

            (Axiom:17606): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
            [New Thread 0xb7d53b70 (LWP 17609)]
            [New Thread 0xb73ffb70 (LWP 17610)]
            [New Thread 0xb6ba7b70 (LWP 17611)]
            Valid QUrl! //Initial QML source is valid
            Changing Picture //Changes picture on background
            Changing Picture //Changes picture on background again
            Application did Finish Launching //Initial setup for the application is complete
            Mouse Click Detected //User clicked on the window canvas, triggers a call to swap the QML source file
            Valid QUrl! //Target QML source file is valid.

            Program received signal SIGSEGV, Segmentation fault.
            0x002c5aa3 in QDeclarativeExpression::hasError() const ()
            from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            (gdb) backtrace
            #0 0x002c5aa3 in QDeclarativeExpression::hasError() const ()
            from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #1 0x00302672 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #2 0x010d5b7d in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #3 0x010e4a6a in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #4 0x003bfde5 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #5 0x0025eccd in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #6 0x0025ee28 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #7 0x00c5c85f in QGraphicsItem::sceneEvent(QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #8 0x002509d3 in QDeclarativeItem::sceneEvent(QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #9 0x0025e14e in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #10 0x00c85cce in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #11 0x00c868fb in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #12 0x00c87317 in QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #13 0x001a69df in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
            #14 0x00c95b3c in QGraphicsScene::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #15 0x005fad84 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #16 0x00600133 in QApplication::notify(QObject*, QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #17 0x010cf19e in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
            ---Type <return> to continue, or q <return> to quit---
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #18 0x005f8b9d in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #19 0x00cb49c8 in QGraphicsView::mouseReleaseEvent(QMouseEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #20 0x00654fc8 in QWidget::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #21 0x00a5a285 in QFrame::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #22 0x00aec821 in QAbstractScrollArea::viewportEvent(QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #23 0x00cb7d04 in QGraphicsView::viewportEvent(QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #24 0x00aeef36 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #25 0x010cf336 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #26 0x005fad52 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #27 0x00600deb in QApplication::notify(QObject*, QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #28 0x010cf19e in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #29 0x005fbd45 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #30 0x00688304 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #31 0x00686e8d in QApplication::x11ProcessEvent(_XEvent*) ()
            from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #32 0x006b328c in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #33 0x01d6f25f in g_main_context_dispatch () from /lib/i386-linux-gnu/libglib-2.0.so.0
            ---Type <return> to continue, or q <return> to quit---
            #34 0x01d6f990 in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
            #35 0x01d6fc2a in g_main_context_iteration () from /lib/i386-linux-gnu/libglib-2.0.so.0
            #36 0x010fdada in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #37 0x006b2e7a in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #38 0x010ce1dd in QEventLoop::processEvents(QFlagsQEventLoop::ProcessEventsFlag) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #39 0x010ce421 in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) ()
            from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #40 0x010d319d in QCoreApplication::exec() () from /usr/lib/i386-linux-gnu/libQtCore.so.4
            #41 0x005f8924 in QApplication::exec() () from /usr/lib/i386-linux-gnu/libQtGui.so.4
            #42 0x0804ab31 in main (argc=1, argv=0xbffff394) at ../Axiom/main.cpp:17
            @

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tjsail33
              wrote on last edited by
              #6

              hopeful bump.... trying to get this all sorted by tomorrow.

              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