Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    3
    8
    4201
    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.
    • T
      ThElitEyeS last edited by

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

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        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 Reply Quote 0
        • T
          ThElitEyeS last edited by

          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 Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            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 Reply Quote 0
            • T
              ThElitEyeS last edited by

              @
              #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 Reply Quote 0
              • raven-worx
                raven-worx Moderators last edited by

                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 Reply Quote 0
                • D
                  dbzhang800 last edited by

                  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 Reply Quote 0
                  • T
                    ThElitEyeS last edited by

                    Alright thanks.

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