Crash when drag&drop fast



  • When I drag an url from my browser into my application, the application crashes sometimes.

    Sometimes means: I can crash it only with the first drag and I have to move the mouse quick into the window and drop it immediate.

    Suse Leap 42.3 64 bit with all updates
    g++ -g -fPIC -I /usr/include/qt5 tst.cpp -lQt5Core -lQt5Widgets -lQt5Gui -lc

    gdb says:

    #0  0x00007ffff78ed84a in QUrlPrivate::isEmpty() const (this=0x79546174654d7451) at io/qurl.cpp:516
    #1  0x00007ffff78ed84a in QUrl::isEmpty() const (this=this@entry=0x7ffff7a38548) at io/qurl.cpp:1864
    #2  0x00007ffff78ed889 in QUrl::isValid() const (this=0x7ffff7a38548) at io/qurl.cpp:1849
    #3  0x00007ffff78f64df in QUrl::toString(QUrlTwoFlags<QUrl::UrlFormattingOption, QUrl::ComponentFormattingOption>) const (this=this@entry=0x7ffff7a38548, options=...) at io/qurl.cpp:3271
    #4  0x00007ffff78f6c5c in QUrl::toDisplayString(QUrlTwoFlags<QUrl::UrlFormattingOption, QUrl::ComponentFormattingOption>) const (this=this@entry=0x7ffff7a38548, options=..., options@entry=...) at io/qurl.cpp:3345
    #5  0x00007ffff78f6ca2 in operator<<(QDebug, QUrl const&) (d=..., url=...) at io/qurl.cpp:3934
    (gdb) up
    #1  QUrl::isEmpty (this=this@entry=0x7ffff7a38548) at io/qurl.cpp:1864
    1864        return d->isEmpty();
    (gdb) print *this
    $1 = {d = 0x79546174654d7451}
    

    So it smells like the d-pointer is really strange, not initialized or overwritten by something?

    Any idea?

    #include <QtCore/qdebug.h>
    #include <QtCore/qmimedata.h>
    #include <QtCore/qurl.h>
    #include <QtGui/qevent.h>
    #include <QtWidgets/qapplication.h>
    #include <QtWidgets/qwidget.h>
    
    class Widget : public QWidget {
    protected:
      virtual void dragEnterEvent(QDragEnterEvent *event);
    };
    
    void Widget::dragEnterEvent(QDragEnterEvent *event) {
      if(event->mimeData()->hasUrls()) {
        QList<QUrl> urls = event->mimeData()->urls();
        for(QList<QUrl>::const_iterator it = urls.cbegin(); it != urls.end(); ++ it) {
          qDebug() << "DragEnter got url" << *it;
        }
      }
      event->acceptProposedAction();
    }
    
    int main(int argc, char **argv) {
      QApplication app(argc, argv);
      Widget w;
      w.setAcceptDrops(true);
      w.show();
      app.exec();
      return 0;
    }
    

  • Moderators

    It looks like your QUrl is out of scope and was cleaned up at some point before you referenced it.

    There isn't enough code to see where it might be happening though.

    Try dumping urls.size() and see if it has the amount you are expecting when the crash happens. My guess is in that url list you are getting an iterator to a URL that was cleaned up already (hence the bad dptr).



  • Strange!

    I downloaded & compiled qt-everywhere-opensource-src-5.6.2 (the same version as the installed one) and cannot reproduce that error? (I just switched the libraries with LD_LIBRARY_PATH, so my code it is the same binary.)



  • Argh!

    Wrong code:

    for(QList<QUrl>::const_iterator it = urls.cbegin(); it != urls.end(); ++ it) {
    

    Working code:

    for(QList<QUrl>::const_iterator it = urls.cbegin(); it != urls.cend(); ++ it) {
    

    Shame on me!

    However, the compiler did not say anything, even with -Wall -W -Wextra :-(


  • Moderators

    @Wurgl Lol I didn't see that one either. I looked at that code in detail too. Just shows how the human brain sees what it thinks should be there unless you really focus.

    Anyway, glad you're all fixed! :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.