Nominate our 2022 Qt Champions!

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)

  • Lifetime Qt Champion

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

  • Moderators

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

    Stack Trace 2

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

    Thank you for the support..

  • Lifetime Qt Champion

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


    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