Results 1 to 6 of 6

Thread: Qt4/C++ - QClipboard - copy & paste to a terminal

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt4/C++ - QClipboard - copy & paste to a terminal

    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.
    Qt Code:
    1. QClipboard *myClip = QApplication::clipboard();
    2. myClip->setText(myCommandString);
    3. tProcess = new QProcess(this);
    4. QString program = ("lxterminal -e");
    5. tProcess->start(program);
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt4/C++ - QClipboard - copy & paste to a terminal

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    jimbo (1st June 2015)

  4. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt4/C++ - QClipboard - copy & paste to a terminal

    Hello wysota,

    Qt Code:
    1. myClip->setText(myCommandString, QClipboard::Mode(QClipboard::Selection));
    To copy to clipboard, switch view to plain text mode 
    Many thanks, works fine.

    Just out of curiosity.
    Or is it possible to paste to the termimal programmatically?
    Regards

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt4/C++ - QClipboard - copy & paste to a terminal

    A terminal is a external application so you would need to send some system event to it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt4/C++ - QClipboard - copy & paste to a terminal

    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

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt4/C++ - QClipboard - copy & paste to a terminal

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. how to copy file to qclipboard?
    By zjf_ha in forum Newbie
    Replies: 1
    Last Post: 13th September 2010, 09:28
  2. copy and paste
    By hubipet in forum Qt Tools
    Replies: 1
    Last Post: 17th July 2009, 06:19
  3. using cut(), copy(), paste()
    By systemz89 in forum Newbie
    Replies: 5
    Last Post: 18th December 2007, 14:47
  4. Replies: 8
    Last Post: 10th November 2006, 09:39
  5. Copy/Paste in TableView
    By bronte in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2006, 21:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.