I have a C++ project that is using QT4. I’ve used QT Designer to build my form, and in the top bar I have "File -> Open Image". The “Open Image” piece is designated by the QT Designer as a QObject with objectName: actionOpen_Image.
How do I go from a user pressing this QObject, to selecting an image and getting its path so I can load it?
Generally, menu items are QAction objects – if you can get your object to be an action, that would be a good first step.
QActions have a signal triggered which is emitted when selected by a user. This signal can be connected to aslotwhich can be part of an existingQObjector custom-defined.To create and object with a
slot, the following example may be helpful:Here, the QFileDialog class is used (via a
staticmethod) to get the name of a file. You can set filters for file types and other useful properties, and the dialog will use the native file-dialog of whatever operating system you’re working with.Use the
connect(QObject* sender, SIGNAL, QObject* receiver, SLOT)method to connect theQAction::triggeredsignal to theslotyou wish to be activated.Actual implementation is up to you of course, hope this can get you started.