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. [SOLVED] QLabel won't update pixmap from inside function
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QLabel won't update pixmap from inside function

Scheduled Pinned Locked Moved General and Desktop
pixmapqt4qpixmap
36 Posts 3 Posters 28.3k Views 2 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 20 Jul 2015, 13:17 last edited by
    #26

    No, not at all. Either:

    1. Remove the widget from MainWindow and connect the one in main.cpp
    2. Remove the one from main.cpp and show the one from MainWindow

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tymer
      wrote on 20 Jul 2015, 13:18 last edited by
      #27

      How would I connect to the instance in main?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 20 Jul 2015, 13:25 last edited by
        #28

        By using the static version of QObject::connect

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tymer
          wrote on 20 Jul 2015, 13:54 last edited by
          #29

          I know this is really basic, but I'm having a bit of a brain fart. I want to make a pointer to the instance I create in main, but I don't want my class to know too much about what's going on in main. How do I do this so that I can create a connection to the object in main from a different widget?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tymer
            wrote on 20 Jul 2015, 15:44 last edited by
            #30

            Right now I have:

            main.cpp

            
            myWidget* w = new myWidget;
            actionTestWindow* t = new actionTestWindow(w, new QWidget);
            

            actionTestWindow.cpp

            actionTestWindow::actionTestWindow(myWidget* Widget, QWidget *parent) :
                QWidget(parent),
                ui(new Ui::actionTestWindow)
                {
                    ui->setupUi(this);
            
                    Widget = new myWidget;
            

            The actionTestWindow is no longer showing, and I think it has something to do with how I insert the QWidget parameter.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 20 Jul 2015, 22:32 last edited by
              #31

              Roll back to before you modified that constructor. Just call '''Widget->show();'''

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tymer
                wrote on 23 Jul 2015, 18:04 last edited by
                #32

                Alright, finally got this problem SOLVED!

                I pass in an instance of myWidget as a parameter of actionTestWindow in main. It's important to note that you need to specify the QWidget as parent = 0 or it will not show. The relevant code looks something like this:

                main.cpp

                QWidget* parent = new QWidget;
                parent = 0;
                myWidget* w = new myWidget;
                actionTestWindow* a = new actionTestWindow(w,parent);
                
                w->show();
                a->show();
                

                actionTestWindow.h

                class actionTestWindow : public QWidget {
                myWidget* m;
                
                public:
                actionTestWindow(myWidget* mW, QWidget* parent = 0);
                

                actionTestWindow.cpp

                actionTestWindow::actionTestWindow(myWidget* mW, QWidget* parent)
                {
                this->m = mW;
                /*use this->m to reference myWidget*/
                }
                

                **note: irrelevant or standard code was mostly emitted.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 23 Jul 2015, 21:57 last edited by
                  #33

                  And there you have a memory leak.

                  Why don't you just show the myWidget you had originally created in Widget ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  T 1 Reply Last reply 27 Jul 2015, 14:42
                  0
                  • S SGaist
                    23 Jul 2015, 21:57

                    And there you have a memory leak.

                    Why don't you just show the myWidget you had originally created in Widget ?

                    T Offline
                    T Offline
                    Tymer
                    wrote on 27 Jul 2015, 14:42 last edited by Tymer
                    #34

                    @SGaist It's a pretty complicated project. The actionTestWindow is pretty much just what it sounds like...A test window. The point is to make sure that I can successfully pass the signals I need and get the reactions I need for when I connect it to a more complicated process. myWidget needs to be shown from main as soon as the program starts running. Having it wait to show until the process that it displays info from runs would be a problem. The code will be passed around to many other people to be changed for future projects, and we're trying to avoid making them dig through code to find things as much as possible. It needs to be easy to just change a class slightly and change the instantiation slightly in order to make a change.

                    Can you point out the exact memory leak? I was under the impression that you can pass in instances of classes as parameters. It's a pretty common thing to do in Java, and I've at least heard of it being done in C++. There is a lot of code omitted. Destructors, importantly.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 27 Jul 2015, 20:22 last edited by
                      #35

                      You have

                      QWidget* parent = new QWidget;
                      parent = 0; << the original parent is now lost and not destroyed
                      myWidget* w = new myWidget;
                      

                      Since it needs to be the first widget, then create it in main. Connect your MainWindow to it also in main.

                      You should rather avoid making that test widget known to any and every widget of your software. Doing so you'll avoid tight coupling and maintenance hell.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Tymer
                        wrote on 27 Jul 2015, 20:57 last edited by
                        #36

                        Changed it to QWidget* parent = 0;. No more memory leak, everything works as expected.

                        1 Reply Last reply
                        0

                        35/36

                        27 Jul 2015, 20:22

                        • Login

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