[SOLVED]How to copy data in clipboard using qt console application
-
wrote on 2 Jul 2013, 22:40 last edited by
As the title says.
Maybe <QClipboard>?
but how i can use it at console application please provide an example. -
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.
-
wrote on 3 Jul 2013, 06:56 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. -
please post your code of your usage of QClipboard.
-
wrote on 3 Jul 2013, 08:00 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();
}
@ -
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);@
-
wrote on 3 Jul 2013, 08:23 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).
-
wrote on 3 Jul 2013, 09:08 last edited by
Alright thanks.
1/8