Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. automatically copy selected text
Forum Updated to NodeBB v4.3 + New Features

automatically copy selected text

Scheduled Pinned Locked Moved General and Desktop
qtexteditselection
12 Posts 4 Posters 9.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    There's no need for that, have a look at copyAvailable and copy

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    ravasR 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi and welcome to devnet,

      There's no need for that, have a look at copyAvailable and copy

      ravasR Offline
      ravasR Offline
      ravas
      wrote on last edited by
      #3

      @SGaist I read those pages, and posted my code based on those functions, and noted a problem.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Sorry, I misunderstood that. What version of Qt 5 are you using ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        ravasR 1 Reply Last reply
        0
        • SGaistS SGaist

          Sorry, I misunderstood that. What version of Qt 5 are you using ?

          ravasR Offline
          ravasR Offline
          ravas
          wrote on last edited by ravas
          #5

          @SGaist 5.4.1 community (windows 7)

          1 Reply Last reply
          0
          • ravasR Offline
            ravasR Offline
            ravas
            wrote on last edited by
            #6

            When I double click on a word it will copy the whole word.
            When I start on the right of the word and drag to select,
            it will copy the right most character;
            starting on the left it will copy the left most character.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #7

              Hi @ravas ,

              Use the selectionChanged() signal instead.

              The copyAvailable() signal is only emitted when you change from available to not-available (or the other way round). It is not emitted when you add more characters to your selection.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              ravasR 1 Reply Last reply
              1
              • JKSHJ JKSH

                Hi @ravas ,

                Use the selectionChanged() signal instead.

                The copyAvailable() signal is only emitted when you change from available to not-available (or the other way round). It is not emitted when you add more characters to your selection.

                ravasR Offline
                ravasR Offline
                ravas
                wrote on last edited by ravas
                #8

                @JKSH I get an error with:

                void Notepad::on_textEdit_selectionChanged()
                {
                    ui->textEdit->copy();
                }
                

                "OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"

                I tried another way:

                void Notepad::on_textEdit_selectionChanged()
                {
                    QTextCursor cursor(ui->textEdit->textCursor());
                    const QString sel = cursor.selectedText();
                    QClipboard *myClip = qApp->clipboard();
                    myClip->setText(sel);
                }
                

                This gives the error "invalid use of incomplete type class QClipboard"...
                I'm not sure how to complete it... ;-]

                ravasR JKSHJ 2 Replies Last reply
                0
                • ravasR ravas

                  @JKSH I get an error with:

                  void Notepad::on_textEdit_selectionChanged()
                  {
                      ui->textEdit->copy();
                  }
                  

                  "OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"

                  I tried another way:

                  void Notepad::on_textEdit_selectionChanged()
                  {
                      QTextCursor cursor(ui->textEdit->textCursor());
                      const QString sel = cursor.selectedText();
                      QClipboard *myClip = qApp->clipboard();
                      myClip->setText(sel);
                  }
                  

                  This gives the error "invalid use of incomplete type class QClipboard"...
                  I'm not sure how to complete it... ;-]

                  ravasR Offline
                  ravasR Offline
                  ravas
                  wrote on last edited by
                  #9

                  I forgot #include <QClipboard>

                  However there is still an error...

                  "OleSetClipboard: Failed to set mime data (text/plain) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"

                  1 Reply Last reply
                  0
                  • ravasR ravas

                    @JKSH I get an error with:

                    void Notepad::on_textEdit_selectionChanged()
                    {
                        ui->textEdit->copy();
                    }
                    

                    "OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"

                    I tried another way:

                    void Notepad::on_textEdit_selectionChanged()
                    {
                        QTextCursor cursor(ui->textEdit->textCursor());
                        const QString sel = cursor.selectedText();
                        QClipboard *myClip = qApp->clipboard();
                        myClip->setText(sel);
                    }
                    

                    This gives the error "invalid use of incomplete type class QClipboard"...
                    I'm not sure how to complete it... ;-]

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #10

                    @ravas said:

                    void Notepad::on_textEdit_selectionChanged()
                    {
                        ui->textEdit->copy();
                    }
                    

                    This code is correct.

                    I tested your code, and it works for me. I used Qt 5.4.1, both MinGW 4.9.1 and MSVC 2013. My OS is Windows 8.1 Pro x64.

                    "OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"

                    This is an error with your Windows clipboard, not with Qt. Make sure that other programs are not trying to use the clipboard at the same time. Try rebooting your computer and see if that helps.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    ravasR 1 Reply Last reply
                    1
                    • JKSHJ JKSH

                      @ravas said:

                      void Notepad::on_textEdit_selectionChanged()
                      {
                          ui->textEdit->copy();
                      }
                      

                      This code is correct.

                      I tested your code, and it works for me. I used Qt 5.4.1, both MinGW 4.9.1 and MSVC 2013. My OS is Windows 8.1 Pro x64.

                      "OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"

                      This is an error with your Windows clipboard, not with Qt. Make sure that other programs are not trying to use the clipboard at the same time. Try rebooting your computer and see if that helps.

                      ravasR Offline
                      ravasR Offline
                      ravas
                      wrote on last edited by
                      #11

                      @JKSH I closed all programs and opened Qt creator again; and now it works... :D
                      Thanks

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        CathyG
                        wrote on last edited by
                        #12

                        I got the Clipboard error when I had RealVncViewer running at the same time. I closed VNC & then the application ran without the clipboard error.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved