I have a Qt program to visualize my data as a voxel grid (see picture below). However I just want to run the Qt program once, such that the data gets displayed, take a screenshot then exit the entire program.
Here is my code:
int main(int argc, char** argv) {
QApplication app(argc, argv);
Mainframe frame(voxelGrid);
frame.show();
app.exec();
frame.saveScreenshot();
return 0;
}
In the above example Mainframe
is a class inheriting from QMainWindow
.
However it seems that I need to call app.exec
or else the saveScreenshot
function will only store a black image. app.exec
however results in an infinite loop and I need to manually close the window before the program continues with the screenshot saving. Any idea how to fix this?
Here is the data that I'm plotting:
using Qt's screenshot function:
QImage img = ui.mViewport->grabFrameBuffer();
img.save("screenshot.png");
QApplication::clipboard()->setImage(img);
where mViewport
is a class inheriting from QGLWidget
.
The entire Qt-Window looks like this: