Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [Solved] Copy text from QString?

    General and Desktop
    3
    6
    4285
    Loading More Posts
    • 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.
    • CAD_coding
      CAD_coding 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.

      1 Reply Last reply Reply Quote 0
      • S
        SetBetterPass 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.

        1 Reply Last reply Reply Quote 0
        • CAD_coding
          CAD_coding 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?

          1 Reply Last reply Reply Quote 0
          • C
            Code_ReaQtor 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

            Please visit my open-source projects at https://github.com/Code-ReaQtor.

            1 Reply Last reply Reply Quote 1
            • S
              SetBetterPass 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.

              1 Reply Last reply Reply Quote 1
              • CAD_coding
                CAD_coding 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!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post