Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Behavior on x Producing SegFault
QtWS25 Last Chance

QML Behavior on x Producing SegFault

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.7k 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

    I think the title is pretty self explanatory. I have a block of code that I would like to put the line @Behavior on x { SmoothedAnimation { duration: 1500 } }@ on, but whenever I add that line the program SegFaults whenever the view is loaded. Any thoughts? Below is the relevant section of code.

    @
    Repeater {
    id: nodeRepeater
    property int nodeWidth: 385
    property int nodeHeight: 300
    property int sideMargins: 150
    model: ["MainNode.qml","ClusterNode.qml","FanView.qml","DemoNode.qml","StudyAbroadNode.qml"]
    Loader {

            id: baseRectangle
            source: modelData
    
            Behavior on width { SmoothedAnimation { duration: 1500 }}
            Behavior on height { SmoothedAnimation { duration: 1500 }}
            // The following two lines both create SegFaults in the program when uncommented.
            //Behavior on x { SmoothedAnimation { duration: 1500 }}
            //Behavior on y { SmoothedAnimation { duration: 1500 }}
    
            width: nodeRepeater.nodeWidth
            height: nodeRepeater.nodeHeight
    
            property bool selected: false
    
            x: {
                //console.log(index + "  :  " + nodeRepeater.count/2)
                if(index===0) {
                    x = appDelegate.getScreenWidth()/2-nodeRepeater.nodeWidth/2
                }
                else {
                    x = (index<((nodeRepeater.count)/2) ? nodeRepeater.sideMargins : appDelegate.getScreenWidth()-(nodeRepeater.sideMargins+nodeRepeater.nodeWidth))
                }
            }
            y: {
                if(index===0) {
                    y = appDelegate.getScreenHeight()/2-nodeRepeater.nodeHeight/2
                }
                else {
                    y = ((index<(nodeRepeater.count/2) ? index : index+0.5-nodeRepeater.count/2)    -((nodeRepeater.count/2)%2))     *((appDelegate.getScreenHeight()-50)/((nodeRepeater.count)/2)) + (((appDelegate.getScreenHeight()-50)/((nodeRepeater.count)/2))-400)/2
                }
            }
    
            MouseArea {
                id: mainArea
                anchors.fill: parent
                onClicked: baseRectangle.changeFocus()
            }
    
            function changeFocus() {
                for(var i = 0; i<nodeRepeater.count; i++)
                {
                    if(i==index) {
                        if(selected)
                        {
                            if(index===0) {
                                x = appDelegate.getScreenWidth()/2-nodeRepeater.nodeWidth/2
                            }
                            else {
                                x = (index<((nodeRepeater.count)/2) ? nodeRepeater.sideMargins : appDelegate.getScreenWidth()-(nodeRepeater.sideMargins+nodeRepeater.nodeWidth))
                            }
                            if(index===0) {
                                y = appDelegate.getScreenHeight()/2-nodeRepeater.nodeHeight/2
                            }
                            else {
                                y = ((index<(nodeRepeater.count/2) ? index : index+0.5-nodeRepeater.count/2)    -((nodeRepeater.count/2)%2))     *((appDelegate.getScreenHeight()-50)/((nodeRepeater.count)/2)) + (((appDelegate.getScreenHeight()-50)/((nodeRepeater.count)/2))-400)/2
                            }
                            width = nodeRepeater.nodeWidth
                            height = nodeRepeater.nodeHeight
                            selected = false
                            for(var j = 0; j<nodeRepeater.count; j++)nodeRepeater.itemAt(j).visible = true
                        }
                        else
                        {
                            nodeRepeater.itemAt(i).x = 100;
                            nodeRepeater.itemAt(i).y = 100;
                            nodeRepeater.itemAt(i).width = appDelegate.getScreenWidth()-200
                            nodeRepeater.itemAt(i).height = appDelegate.getScreenHeight() -200
                            selected = true
                            for(var j = 0; j<nodeRepeater.count; j++)
                            {
                                if(j==index) continue
                                nodeRepeater.itemAt(j).visible = false
                            }
                        }
                    }
                }
            }
    

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      Can you provide a more minimal example? Without being able to create the item (due to missing the component qml files) I personally don't know what could be causing the problem.

      Also, can you provide a backtrace?

      Thanks!

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

        for a more minimal example, you can just change the Loader element to a Rectangle and comment out the Loader's source assignment. This will remove the need for the external QML files, but keep the functionality I need from the program intact. Below is a backtrace from gdb.

        @

        Program received signal SIGSEGV, Segmentation fault.
        0x002d93c8 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
        (gdb) bt
        #0 0x002d93c8 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
        #1 0x002d93b8 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
        #2 0x002d93b8 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
        #3 0x002d93b8 in ?? () from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
        #4 0x002daa2e in QDeclarativeContext::setContextProperty(QString const&, QObject*) ()
        from /usr/lib/i386-linux-gnu/libQtDeclarative.so.4
        #5 0x0804e09f in MainWindow::swapView (this=0xbffff2c8, view=1) at ../Axiom/AppDelegate.cpp:89
        #6 0x0804ecfa in Slideshow::changeToMainView (this=0x8326228) at ../Axiom/SlideshowViewController.cpp:52
        #7 0x080cb414 in Slideshow::qt_metacall (this=0x8326228, _c=QMetaObject::InvokeMetaMethod, _id=2,
        _a=0x81c72f0) at moc_SlideshowViewController.cpp:80
        #8 0x010dab7d in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #9 0x010e5685 in QMetaCallEvent::placeMetaCall(QObject*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #10 0x010ecb52 in QObject::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #11 0x005ffd84 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
        from /usr/lib/i386-linux-gnu/libQtGui.so.4
        #12 0x00605133 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
        #13 0x010d419e in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #14 0x010d7f93 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #15 0x010d80ec in QCoreApplication::sendPostedEvents(QObject*, int) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        ---Type <return> to continue, or q <return> to quit---
        #16 0x011026a4 in ?? () from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #17 0x01d7425f in g_main_context_dispatch () from /lib/i386-linux-gnu/libglib-2.0.so.0
        #18 0x01d74990 in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
        #19 0x01d74c2a in g_main_context_iteration () from /lib/i386-linux-gnu/libglib-2.0.so.0
        #20 0x01102ada in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #21 0x006b7e7a in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
        #22 0x010d31dd in QEventLoop::processEvents(QFlagsQEventLoop::ProcessEventsFlag) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #23 0x010d3421 in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) ()
        from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #24 0x010d819d in QCoreApplication::exec() () from /usr/lib/i386-linux-gnu/libQtCore.so.4
        #25 0x005fd924 in QApplication::exec() () from /usr/lib/i386-linux-gnu/libQtGui.so.4
        #26 0x080ca586 in main (argc=1, argv=0xbffff3a4) at ../Axiom/main.cpp:20
        @

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chriadam
          wrote on last edited by
          #4

          Are you able to use a debug version of QtDeclarative? From that backtrace it's difficult to see what's going on. I tried to reproduce given your instructions (with Qt4.8 built from git), but while I get various warnings:

          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:14: ReferenceError: Can't find variable: nodeRepeater
          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:28: ReferenceError: Can't find variable: index
          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:20: ReferenceError: Can't find variable: index
          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:13: ReferenceError: Can't find variable: nodeRepeater

          I then tried with QtQuick 2.0 (latest QtDeclarative from git) and got similar warnings but again no crash:

          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:28: ReferenceError: index is not defined
          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:20: ReferenceError: index is not defined
          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:14: ReferenceError: nodeRepeater is not defined
          file:///home/chriadam/depot/testdpl/segfaultonbehaviour/test.qml:13: ReferenceError: nodeRepeater is not defined

          I don't get any segmentation fault.

          Cheers,
          Chris

          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