[SOLVED] How can I used the same thread without having to create a new one ??
-
I'm not sure if I'm even deleting the image correctly.
QDesktopWidget* dw = QApplication::desktop(); QPixmap pixmap = QPixmap::grabWindow( dw->winId(), 0, 0, dw->width(), dw->height() ); QDir mDir(QDir::homePath()); QString format = "jpg"; QString filename = "/perfq_" + QString::number(QDate::currentDate().year())+ "_" +QString::number(QDate::currentDate().month())+ "_" +QString::number(QDate::currentDate().day())+ "_" +QString::number(QTime::currentTime().hour())+ "_" +QString::number(QTime::currentTime().minute())+ "_" +QString::number(QTime::currentTime().second()); QString mPath = QDir::homePath() + "/perfq_id_" + QString::number(this->idu); if (!mDir.exists(mPath)) mDir.mkpath(mPath); pixmap.save(mPath+filename+".jpg", format.toLatin1().constData());
however how can I use the QThreadPool ??
-
You are using Qt 4.8. The links I had provided are for Qt 5. grabWindow is not defined for QPixMap in Qt 5.
Here is the link for the proper Qt 4.8 QThreadPool documentation.I though that you might allocate memory for the picture and do not release properly. I cannot see a reason either.
With QThreadPool I have to stay out of discussion. Probably I do not know more about threading than you do.
-
Good to know that you have fixed your problem.
My conclusion was that you are using Qt4 since you use grabWindow which I could not find in Qt 5 documentation.
However, grabWindow and grabWidget are marked as obsolete in Qt 5. Apparently, those are still working, but this may be something to be changed, since there is no real support anymore. -
@SujaMM
Checkout the Qt5 screenshot example.
It usesQGuiApplication::primaryScreen()
to take the screenshot. pimaryScreen There is also screens() and other stuff. -
I try this before I use this code:
QApplication a(argv, argc); QScreen *screen = a.primaryScreen(); QPixmap screenshot = screen->grabWindow(0); screenshot.save('screenshot.png', 'png'); QList<QScreen*> screens = a.screens(); QScreen *screen; QPixmap screenshot; for(int i = 0; i < screens.length(); i++){ screen = screens.at(i); screenshot = screen->grabWindow(0); screenshot.save(QString::number(i) + ".png", 'png'); }
but it will take various screenshots of the primary screen.