PDA

View Full Version : Qt4/C++ - QClipboard - copy & paste to a terminal



jimbo
1st June 2015, 13:42
Hello,

Debian 'Wheezy' - Qt4 - C++

I'm calling a system teminal and I can paste the clipbord contents into the terminal with a mouse right click & paste.
OK so far.
QClipboard *myClip = QApplication::clipboard();
myClip->setText(myCommandString);
tProcess = new QProcess(this);
QString program = ("lxterminal -e");
tProcess->start(program);Would it be possible to use the centre mouse button to paste, as is normal in linux?
Or is it possible to paste to the termimal programmatically?
I would like the terminal to stay visible after the paste as 'myCommandString' expects a user response.

Regards

wysota
1st June 2015, 14:11
On unix systems there are two separate clipboards available -- Clipboard and Selection. The first one is the one related to Ctrl+C, Ctrl+V, the other one is handled with the middle mouse button.

jimbo
1st June 2015, 14:53
Hello wysota,


myClip->setText(myCommandString, QClipboard::Mode(QClipboard::Selection));Many thanks, works fine.

Just out of curiosity.

Or is it possible to paste to the termimal programmatically?

Regards

wysota
1st June 2015, 18:03
A terminal is a external application so you would need to send some system event to it.

jimbo
3rd June 2015, 12:31
Hello wysota,

No problems, working fine.
A last question, should I clear the clipboard on program close or will it clear and free memory automatically?

Regards

wysota
3rd June 2015, 13:34
Clipboard belongs to the system. It is the one deciding what happens with its contents. If you want to clear it (e.g. because of sensitivity of the information or its scope) then you can of course do that if you want.