massagebion.blogg.se

Imageviewer null image
Imageviewer null image










imageviewer null image

Unless the file name is a empty string, we check if the file's format is an image format by constructing a QImage which tries to load the image from the file. If the user presses Cancel, QFileDialog returns an empty string. If the file could not be opened, we use QMessageBox to display a dialog with an error message. It returns the file path of the file selected, or an empty string if the user canceled the dialog. The static getOpenFileName() function displays a modal file dialog. Qt comes with QFileDialog, which is a dialog from which the user can select a file. The first step is asking the user for the name of the file to open. QDebug() setPixmap(QPixmap::fromImage(image)) We want to implement the functionality of the on_actionOpen_triggered() slot.

#IMAGEVIEWER NULL IMAGE CODE#

It's not necessary but we just want to have the same code in the Qt Example.ĭo the same to all the actions triggered.Īlso, we need to put the pointers to those actions into imageviewer.h:įrom this point, the remaining process is almost the same as the original Qt tutorial. Let's switch the name of the slot to open() as shown earlier in the equivalent code. Then, it will generate a code for us into imageviewer.cpp:ĭesigner also writes the slot declaration to the header file, imageviewer.h, as well. Right click on the openAtc in the Action Editor, and select "Go to slot." Let's open up Designer by double-clicking the imageviewer.ui to connect actions to slots. The equivalent code is shown below:Ĭonnect(openAct, SIGNAL(triggered()), this, SLOT(open())) Ĭonnect(printAct, SIGNAL(triggered()), this, SLOT(print())) Ĭonnect(exitAct, SIGNAL(triggered()), this, SLOT(close())) Ĭonnect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn())) Ĭonnect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut())) Ĭonnect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize())) Ĭonnect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow())) Ĭonnect(aboutAct, SIGNAL(triggered()), this, SLOT(about())) Ĭonnect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())) We're going to connect each action to a appropriate slot using Qt Designer.












Imageviewer null image