Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    [Solved] Error: Invalid use of member (...) in static member function

    QML and Qt Quick
    4
    8
    14715
    Loading More Posts
    • 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.
    • E
      Endless last edited by

      I have a UI window created in UI Designer called MonitorWindow. It has a child widget called DualDial. Basically what I'm doing is drawing 2 dials on the MonitorWindow. One is like a second hand, and the other is like a minute hand on a clock. These dials are updated with a timer (that's called by DualDial) that goes off every 100ms. All of this works fine. On the MonitorWindow UI, there's also a text label, timeLabel, that displays the current time, and I want to update that label with the timer that's running in DualDial. I've connected a signal, timeChanged, to a slot called UpdateTimeSlot in MonitorWindow. Here's the monitorwindow.h file:
      @
      namespace Ui {
      class MonitorWindow;
      }
      class MonitorWindow : public QWidget
      {
      Q_OBJECT
      public:
      explicit MonitorWindow(QWidget *parent = 0);
      ~MonitorWindow();
      Ui::MonitorWindow *ui;
      public slots:
      static void UpdateTimeSlot();
      };
      @
      Then, in the MonitorWindow constructor, I instatiate the child widget called DualDial:
      @
      DualDial *dualdial = new DualDial(this);
      @
      In the DualDial constructor, I connect the signal to the slot:
      @
      connect(this, timeChanged(), parent, MonitorWindow::UpdateTimeSlot());
      @
      The timeChanged signal is emitted inside the timer function for DualDial, so this should call MonitorWindow::UpdateTimeSlot. Inside that function I create a string called timeStr and then just update the timeLabel in the UI with the new string:
      @
      ui->timeLabel->setText(timeStr);
      @
      When I try to compile, it gives me the error: invalid use of member 'MonitorWindow::ui' in static member function. It points to the line of code above. What am I doing wrong?

      1 Reply Last reply Reply Quote 0
      • V
        vsorokin last edited by

        Why you want ahve static slot?

        --
        Vasiliy

        1 Reply Last reply Reply Quote 0
        • E
          Endless last edited by

          When the UpdateTimeSlot wasn't static, I got the error: "cannot call member function 'MonitorWindow::UpdateTimeSlot()' without object" when I tried to connect the signal and the slot:
          @
          connect(this, timeChanged(), parent, MonitorWindow::UpdateTimeSlot());
          @

          1 Reply Last reply Reply Quote 0
          • V
            vsorokin last edited by

            I guess parent is pointer to MonitorWindow instance. right?
            When you need:

            @connect(this, SIGNAL(timeChanged()), parent, SLOT(UpdateTimeSlot()));@

            and remove static

            --
            Vasiliy

            1 Reply Last reply Reply Quote 0
            • E
              Endless last edited by

              It then tells me that UpdateTimeSlot was not declared in this scope. Here's the beginning of the dualdial.cpp file with the constructor:
              @
              #include "dualdial.h"
              #include "global.h"
              #include "monitorwindow.h"

              DualDial::DualDial(QWidget *parent) :
              QWidget(parent)
              {
              move(465, 100);
              resize(400, 150);
              connect(this, timeChanged(), parent, UpdateTimeSlot());
              QTimer *timer = new QTimer(this);
              connect(timer, SIGNAL(timeout()), this, SLOT(update()));
              timer->start(10);
              }
              @
              And if you need it, here's the dualdial.h file:
              @
              #include <QtGui>

              class DualDial : public QWidget
              {
              Q_OBJECT
              public:
              explicit DualDial(QWidget *parent = 0);
              signals:
              void timeChanged();
              protected:
              void paintEvent(QPaintEvent *);
              };
              @

              1 Reply Last reply Reply Quote 0
              • M
                mlong last edited by

                At first glance, in line 10, you need to wrap your signal and slot names in SIGNAL and SLOT macros.

                @
                    connect(this, SIGNAL(timeChanged()), parent, SLOT(UpdateTimeSlot()));
                @

                There may be other issues, but this one is important.

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply Reply Quote 0
                • E
                  Endless last edited by

                  And here I thought it was some heavy C++ issue that I wouldn't understand. :o) It was right there in front of me!! Thanks both of you for your help!

                  1 Reply Last reply Reply Quote 0
                  • B
                    Bove523 Banned last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post