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. [SOLVED]How to copy data in clipboard using qt console application
Forum Update on Monday, May 27th 2025

[SOLVED]How to copy data in clipboard using qt console application

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.8k Views
  • 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.
  • T Offline
    T Offline
    ThElitEyeS
    wrote on 2 Jul 2013, 22:40 last edited by
    #1

    As the title says.
    Maybe <QClipboard>?
    but how i can use it at console application please provide an example.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 3 Jul 2013, 06:44 last edited by
      #2

      Are you using QCoreApplication or QApplication?
      The QClipboard instance is only available with QApplication.
      Thus your console application gets an gui application once you decide to use QApplication. But if you don't mind the overhead it shouldn't make a difference for you in general (you can still code a console application).

      For an example usage of QClipboard see the docs.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThElitEyeS
        wrote on 3 Jul 2013, 06:56 last edited by
        #3

        I am using QCoreApplication
        And i tried QClipboard at the console application it was giving no errors but it was not working too.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 3 Jul 2013, 07:48 last edited by
          #4

          please post your code of your usage of QClipboard.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • T Offline
            T Offline
            ThElitEyeS
            wrote on 3 Jul 2013, 08:00 last edited by
            #5

            @
            #include <QCoreApplication>
            #include <QDebug>
            #include <QtNetwork>
            #include <QClipboard>
            #include <QApplication>
            main(int argc, char *argv[])
            {
            QCoreApplication a(argc, argv);
            QNetworkAccessManager manager;
            QNetworkRequest request(QUrl("http://google.com"));
            QNetworkReply *reply(manager.get(request));
            QEventLoop loop;
            QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
            loop.exec();
            QClipboard *qc = QApplication::clipboard();
            qc->setText(reply->readAll());
            qDebug() << "1asdasd";
            return a.exec();
            }
            @

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 3 Jul 2013, 08:13 last edited by
              #6

              well... as i wrote in my first post. QClipboard is only available through QApplication. And still you use QCoreApplication.
              I tried your code and it works like expected with QApplication....

              @QApplication a(argc, argv); //instead of QCoreApplication a(argc, argv);@

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dbzhang800
                wrote on 3 Jul 2013, 08:23 last edited by
                #7

                The reason is that QClipBoard depends on the initialization of the QApplication(or QGuiApplication).

                Take windows as an example, QClipBoard depends on the AcitveX/COM components of the system, which get initialized in the constructor of QApplication(or QGuiApplication).

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  ThElitEyeS
                  wrote on 3 Jul 2013, 09:08 last edited by
                  #8

                  Alright thanks.

                  1 Reply Last reply
                  0

                  1/8

                  2 Jul 2013, 22:40

                  • Login

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