Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QApplication::clipboard()->setMimeData causing the QT application to crash



  • Is there an issue with QApplication::clipboard()->setMimeData being used in very quick succession? Observed that the application crashes when the QApplication::clipboard()->setMimeData is made use of to update the clipboard very frequently( for eg: 10 cut operations per second)?

    Is there a way that can be suggested to give a throttling effect to the very frequent user operations? (Like restricting the Clipboard update to occur, say once in 500 ms rather at the user defined pace)


  • Qt Champions 2019

    Please show the backtrace. Maybe QApplication::clipboard() returns a nullptr?


  • Moderators

    @PradeepJoy
    show the code where you create and insert the QMimeData object into the clipboard.
    Note that the clipboard takes ownership of the mimedata object and thus shouldn't have a parent nor destroyed prematurely.



  • @Christian-Ehrlicher , @raven-worx
    We are using qt version 4.7.3 (if this helps)

    Code Pointer


    QMimeData *mimeData = new QMimeData;
    QString strToCopy = defToDrag.isEmpty() ? textToDrag : (defToDrag + "{}" + textToDrag);
    mimeData->setText(strToCopy);
    QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
    QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
    

    We are not destroying mimeData anywhere..

    We are able consistently replicate the crash. Attaching couple of stack traces we observed,
    Stack Trace 1


    #0 0x00002aaaab1a1b0e in ?? () from /libQtGui.so.4
    #1 0x00002aaaab213304 in QClipboard::event(QEvent*) () from /libQtGui.so.4
    #2 0x00002aaaab18b6af in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /libQtGui.so.4
    #3 0x00002aaaab190e30 in QApplication::notify(QObject*, QEvent*) () from /libQtGui.so.4
    #4 0x00002aaaaac64364 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /libQtCore.so.4
    #5 0x00002aaaab20ac3b in QApplication::x11ProcessEvent(_XEvent*) () from /libQtGui.so.4
    #6 0x00002aaaab233622 in ?? () from /libQtGui.so.4
    #7 0x0000003cf6640555 in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
    #8 0x0000003cf6644d08 in ?? () from /lib64/libglib-2.0.so.0
    #9 0x0000003cf6644ec2 in g_main_context_iteration () from /lib64/libglib-2.0.so.0
    #10 0x00002aaaaac8fd15 in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () from /libQtCore.so.4
    #11 0x00002aaaab23316f in ?? () from /libQtGui.so.4
    #12 0x00002aaaaac63715 in QEventLoop::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () from /libQtCore.so.4
    #13 0x00002aaaaac6397d in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) () from /libQtCore.so.4
    #14 0x00002aaaaac65176 in QCoreApplication::exec() () from /libQtCore.so.4

    Stack Trace 2


    #0 0x00002aaaab211319 in QClipboard::setMimeData(QMimeData*, QClipboard::Mode) () from ../libQtGui.so.4
    #1 0x00000000008b1013 in MyClass::slotCut (this=0x18860d0, Cut=true, includeValues=false) at MyClass.C:2511

    Thank you for the support..


  • Qt Champions 2019

    @PradeepJoy said in QApplication::clipboard()->setMimeData causing the QT application to crash:

    QApplication::clipboard()

    So, did you check whether it returns nullptr as @Christian-Ehrlicher suggested?



  • @jsulm QApplication::clipboard() was not returning a null pointer.


Log in to reply