[SOLVED]How to copy data in clipboard using qt console application
As the title says.
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.
main(int argc, char *argv)
QCoreApplication a(argc, argv);
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QClipboard *qc = QApplication::clipboard();
qDebug() << "1asdasd";
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);@
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).