[Solved] Copy text from QString?
-
wrote on 1 Apr 2013, 07:31 last edited by
Hi,
I want to copy the text from a QString (if possible along with the formating?) so that it can be pasted outside my application.
For example, when the string is copied through code then I can paste the string to say notepad.
How do I do that?
I tried by creating a QLineEdit object, setting the text from QString & then QLineEdit::copy();
But it does not work.
Thank You. -
wrote on 1 Apr 2013, 10:23 last edited by
QLineEdit::copy() copies content to clipboard. If you want use this you have to manually paste it to notepad as notepad isn't part of your application.
Take a look "here":https://qt-project.org/doc/qt-4.8/intro-to-dbus.html and "here":https://qt-project.org/doc/qt-4.8/qtdbus.html if you want work with inter-process communication. But this is unix only I don't know what libs are for windows. -
wrote on 1 Apr 2013, 10:31 last edited by
Hi SetBetterPass,
I wanted to copy from a QString not a QLineEdit in the first place.
Since I could not find any function in QString which could help me copy to clipboard.
I thought of a workaround of creating a QLineEdit object & then using copy from it.
However since I had created the object statically which went out of scope after the copy call.
That is why I think it could was not available while pasting to notepad.
Is this the standard way of copying to clipboard in Qt?
So do I have to main a dummy QLineEdit in heap memory all throughout the Application just for the purpose of copying to clipboard? -
wrote on 1 Apr 2013, 10:40 last edited by
Check out "QClipboard":http://qt-project.org/doc/qt-4.8/qclipboard.html
It can be done using "QClipboard::setText()":http://qt-project.org/doc/qt-4.8/qclipboard.html#setText -
wrote on 1 Apr 2013, 11:04 last edited by
Ah sorry I misunderstood your problem, I thought you want to copy it directly to notepad. So if you want copy it to clipboard just check doc posted by Code_ReaQtor.
By the way to copy from QLineEdit you have to use QLineEdit::selectAll() and then you can copy it. QLineEdit::copy() copies only selected text not all text, so you have to select it. -
wrote on 1 Apr 2013, 11:33 last edited by
@Code_ReaQtor Thank You for that information!
@SetBetterPass ohhh I didnt know that.
Maybe it was foolish of me to forget such an obvious thing :P
Thanks!
5/6