Nominate our 2022 Qt Champions!

[SOLVED] Application crashes on clipboard copy or cut (but not paste)

  • An application I am developing crashes when either cut or copy is used, yet somehow paste is not affected.

    UPDATE It occurs when using QInputDialog::getText(...), but not for QInputDialog::getMultiLineText(...).

    It does not crash on my development machine (windows 7, Qt 5), however it does on my other PC (windows 7, Qt 5). Unfortunately the crash information is very limited, right after cut or copy is issued, a window pops up saying 'A problem caused the program to stop working correctly. Please close the program.'.
    Oddly enough it does not happen with other apps I've developed, even though they use the same call to QInputDialog::getText(...).

    Any ideas on what could cause the crashing?

  • Just curious, why are you using QInputDialog::getText to copy?

    I'm my qt apps, I don't code anything and copy/pasting from a field to another works out of the box with Qt?

  • I wasn't using QInputDialog::getText(...) to copy, its the QInputDialog convenience function to get a single line of text (ie. it pops-up a dialog box with a QLineEdit).

  • Oh I see, never used this before.

    So it crash as soon as you copy some text inside the QInputDialog?
    Fast like that.. I'm thinking maybe string encoding problem?
    does it crash on every input you paste ?

  • Found the solution... the problem was an error in my QThread.
    It uses QAxObject to communicate with Excel.

    Anyway, on starting the thread 'run()' I called 'CoInitialize(NULL)', and then for simplicity I had a call to 'CoUninitialize()' in the thread destructor.
    Once I moved the 'CoUnitialize()' call to the 'run()' function (at every exit point), everything works fine.

    Strange how it only seemed to mess with the clipboard.

  • Great that you found it :) good luck!

Log in to reply