Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTCreator opengl mainwindow app - how to pass toolbar events into my sublcassed qglwidget?
I created my first QT opengl app (4.8.3), and it displays the hardcoded png file just fine. Now I want to use the QFileDialog and select different image files. I've created a method in my glwidget class to receive the new filename, but this class has no visibility in the MainWindow. Even with slots & signals, I have nothing to hang the call on in my MainWindow.
Figured it out with a little c++ obfuscation.
in my mainwindow.cpp definition
the method that gets the filename from the QFileDialog - after pressing a toolbar button that calls this slot:
QString strFilename = QFileDialog::getOpenFileName(this, "Open File", "", "Files (.)");
QWidget *cw = centralWidget();
if (strFilename.length() > 0)
In my glwidget.h file,
int loadImage(QString & filename);
and in the glwidget.cpp file there is a method definition.
In the VS2010 debug environment, the call went through to the method definition code.
Boy my reply looks ugly. How do folks post code that looks like code in this forum?
Let me prettify that for you... by sprinkling code markups over your post:-) Check the icons on top of the message window. The one to the far right is the one you want.
wspilot last edited by
You could create an ordinairy mainwindow (Qtcreator will do that for you when you create a new project) and add an QGLWidget as child:
OGLWin = new OGLWindow(...)
This way you can handle all the GUI stuff via the mainwindow and the OpenGl stuff in the QGLWidget.