[SOLVED]How to copy data in clipboard using qt console application
-
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.
-
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.
-
@
#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);@
-
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).
-
Alright thanks.