Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Error: Invalid use of member (...) in static member function

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

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 16.8k Views
  • 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 Offline
    E Offline
    Endless
    wrote on 30 Sept 2011, 16:18 last edited by
    #1

    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
    0
    • V Offline
      V Offline
      vsorokin
      wrote on 30 Sept 2011, 16:20 last edited by
      #2

      Why you want ahve static slot?

      --
      Vasiliy

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on 30 Sept 2011, 16:40 last edited by
        #3

        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
        0
        • V Offline
          V Offline
          vsorokin
          wrote on 30 Sept 2011, 16:57 last edited by
          #4

          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
          0
          • E Offline
            E Offline
            Endless
            wrote on 30 Sept 2011, 17:13 last edited by
            #5

            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
            0
            • M Offline
              M Offline
              mlong
              wrote on 30 Sept 2011, 17:27 last edited by
              #6

              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
              0
              • E Offline
                E Offline
                Endless
                wrote on 30 Sept 2011, 18:20 last edited by
                #7

                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
                0
                • B Offline
                  B Offline
                  Bove523
                  Banned
                  wrote on 12 Apr 2018, 06:17 last edited by
                  #8
                  This post is deleted!
                  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