Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTCreator opengl mainwindow app - how to pass toolbar events into my sublcassed qglwidget?
Forum Updated to NodeBB v4.3 + New Features

QTCreator opengl mainwindow app - how to pass toolbar events into my sublcassed qglwidget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pmaynard
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pmaynard
      wrote on last edited by
      #2

      Figured it out with a little c++ obfuscation.

      in my mainwindow.cpp definition
      @
      #include "glwidget.h"
      @

      the method that gets the filename from the QFileDialog - after pressing a toolbar button that calls this slot:
      @
      void MainWindow::on_actionLoadImage_triggered()
      {
      QString strFilename = QFileDialog::getOpenFileName(this, "Open File", "", "Files (.)");
      QWidget *cw = centralWidget();
      if (strFilename.length() > 0)
      ((glwidget *)cw)->loadImage(strFilename);
      }
      @
      In my glwidget.h file,
      @
      public slots:
      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pmaynard
        wrote on last edited by
        #3

        Boy my reply looks ugly. How do folks post code that looks like code in this forum?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wspilot
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved