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. QUrlList crash using iterator.

QUrlList crash using iterator.

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.8k Views 2 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.
  • conradjonesC Offline
    conradjonesC Offline
    conradjones
    wrote on last edited by conradjones
    #1

    I have a treeview on one window with a QFileSystemModel and dragging from this to another window crashes with the following code

    // This crashes
        if (event->mimeData()->hasUrls()) {
            QList<QUrl>::iterator i = event->mimeData()->urls().begin();
            while (i != event->mimeData()->urls().end()) {
                qDebug() << (*i).path()<< endl;
                i++;
            }
        }
        // This does not
        if (event->mimeData()->hasUrls()) {
            QList<QUrl> urlList = event->mimeData()->urls();
            for (int i = 0; i < urlList.size(); ++i) {
                qDebug() << urlList.at(i).path()<< endl;
            }
        }
    }
    

    I've uploaded a demo project here.

    https://github.com/conradjones/qt-list-crash

    K 1 Reply Last reply
    0
    • conradjonesC conradjones

      I have a treeview on one window with a QFileSystemModel and dragging from this to another window crashes with the following code

      // This crashes
          if (event->mimeData()->hasUrls()) {
              QList<QUrl>::iterator i = event->mimeData()->urls().begin();
              while (i != event->mimeData()->urls().end()) {
                  qDebug() << (*i).path()<< endl;
                  i++;
              }
          }
          // This does not
          if (event->mimeData()->hasUrls()) {
              QList<QUrl> urlList = event->mimeData()->urls();
              for (int i = 0; i < urlList.size(); ++i) {
                  qDebug() << urlList.at(i).path()<< endl;
              }
          }
      }
      

      I've uploaded a demo project here.

      https://github.com/conradjones/qt-list-crash

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @conradjones

      Both code sections do not do exactly the same thing for lists longer than 32 entries. Is there already the reason for your crash?

      Personally, I would hold the list for the first example seaparetely anyhow. There you can check the size of teh list and add a counter in your while loop.

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

      1 Reply Last reply
      0
      • conradjonesC Offline
        conradjonesC Offline
        conradjones
        wrote on last edited by conradjones
        #3

        @koahnig I've updated the example.

        You are however correct about holding the list locally. This works. Interesting, I was trying to avoid copying constructing the whole list. I still see this as a bug.

            if (event->mimeData()->hasUrls()) {
                QList<QUrl> urlList = event->mimeData()->urls();
                QList<QUrl>::iterator i = urlList.begin();
                while (i != urlList.end()) {
                    qDebug() << (*i).path()<< endl;
                    i++;
                }
            }
        
        K 1 Reply Last reply
        0
        • conradjonesC conradjones

          @koahnig I've updated the example.

          You are however correct about holding the list locally. This works. Interesting, I was trying to avoid copying constructing the whole list. I still see this as a bug.

              if (event->mimeData()->hasUrls()) {
                  QList<QUrl> urlList = event->mimeData()->urls();
                  QList<QUrl>::iterator i = urlList.begin();
                  while (i != urlList.end()) {
                      qDebug() << (*i).path()<< endl;
                      i++;
                  }
              }
          
          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @conradjones

          It looks like a bug, assuming that the list may not be changed during your while loop either through event or mimedata. However, you are the only one who can know that part.

          Bugs need to be reported to JIRA

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

          conradjonesC 1 Reply Last reply
          0
          • K koahnig

            @conradjones

            It looks like a bug, assuming that the list may not be changed during your while loop either through event or mimedata. However, you are the only one who can know that part.

            Bugs need to be reported to JIRA

            conradjonesC Offline
            conradjonesC Offline
            conradjones
            wrote on last edited by
            #5

            @koahnig It probably is being changed and the iterator becoming invalidated. Not by me by QT, all I'm doing is handling the drag enter event. I haven't got any threads happening.

            1 Reply Last reply
            0
            • conradjonesC Offline
              conradjonesC Offline
              conradjones
              wrote on last edited by
              #6

              Bug report. : https://bugreports.qt.io/browse/QTBUG-61094

              1 Reply Last reply
              1
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                There is no bug, to sum up the comment on the bug report: in your crashing case you are working with different lists on each iteration.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                3

                • Login

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