I exactly copied all the stuff from the Image Viewer example of Qt, except for the constructor. I modified it the constructor so it would auto load an image coming from another mainwindow that calls
ImageViewer imageViewer(&image);
ImageViewer imageViewer(&image);
To copy to clipboard, switch view to plain text mode
Now I am having trouble with the class because it closes/quits... and I am sure that that class's method show() ( opens for x milliseconds then closes).
I've read this
http://www.qtcentre.org/forum/f-qt-p...t=QApplication
and it says two QApplication can't run at the same time. So how am I going to let the ImageViewer window stay (not instantly quit on show()). ? Because as of now I can't manually close it.. it closes on itself?
Here goes the modified constructor of ImageViewer.
ImageViewer
::ImageViewer(const QImage *image
) { imageLabel
->setBackgroundRole
(QPalette::Base);
imageLabel->setScaledContents(true);
scrollArea
->setBackgroundRole
(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
createActions();
createMenus();
setWindowTitle(tr("Image Viewer"));
resize(500, 400);
// this is where the opening of the passed const image starts
if (image->isNull() || image == 0) {
tr("Cannot load the image."));
return;
}
imageLabel->setPixmap(pixmap);
scaleFactor = 1.0;
printAct->setEnabled(true);
fitToWindowAct->setEnabled(true);
updateActions();
if (!fitToWindowAct->isChecked())
imageLabel->adjustSize();
// suddenly closes ! ! !
show();
}
ImageViewer::ImageViewer(const QImage *image) {
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
createActions();
createMenus();
setWindowTitle(tr("Image Viewer"));
resize(500, 400);
// this is where the opening of the passed const image starts
if (image->isNull() || image == 0) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load the image."));
return;
}
QPixmap pixmap = QPixmap::fromImage(*image);
imageLabel->setPixmap(pixmap);
scaleFactor = 1.0;
printAct->setEnabled(true);
fitToWindowAct->setEnabled(true);
updateActions();
if (!fitToWindowAct->isChecked())
imageLabel->adjustSize();
// suddenly closes ! ! !
show();
}
To copy to clipboard, switch view to plain text mode
I've also read http://www.qtcentre.org/forum/f-qt-p...ght=maptoscene so. how do I NOT destroy the ImageViewer after calling its constructor?
Bookmarks