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. Errors I am getting in my class definition of Qt Widget Application
Forum Updated to NodeBB v4.3 + New Features

Errors I am getting in my class definition of Qt Widget Application

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • F Offline
    F Offline
    Flurite
    wrote on last edited by
    #1

    Hi,

    I've been working with QTimer for my timer application, but I've run into trouble when defining my Stopwatch class in the header file. This is my class definition:
    @
    class Stopwatch : public QObject
    {
    private:
    QTimer timer;
    Clock_Application* ui;
    public:
    Stopwatch();
    private slots:
    void changeTime();
    };

    Stopwatch::Stopwatch()
    {
    connect(&timer, SIGNAL(timeout()), this, SLOT(changeTime()));
    timer.start(1000);
    }

    void Stopwatch::changeTime()
    {
    /* code that tries to access widgets */
    }
    @

    The error I am getting (occurs in changeTime() function) when running my code is this:

    error: 'class Clock_Application' has no member named 'Output'

    The question is how do I get access to my widgets from a class that is NOT the starting class.

    P.S. The changeTime() function is a bit lengthy, but if you need to see it, I will post it.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gmaro
      wrote on last edited by
      #2

      Hi,

      I think you may consider some redesign.

      Some example how to do this in clean way:

      @
      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();

      private:
      ClockWidget *clockWidget;
      Stopwach *stopwatch;
      };
      @

      now you're connecting necessary signals and slots in the MainWindow class. In this way you're having object independency.

      If you're insist on access to widget into your stopwatch, pass ClockWidget pointer to it ie.

      @
      class Stopwatch : public QObject
      {
      ...
      private:
      ClockWidget *clockwidget
      ...
      public:
      Stopwatch(ClockWidget *c) : clockwidget(c)
      ...
      }
      @

      Depends what excatly you need from ClockWidget i can give you more detailed advise.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Flurite
        wrote on last edited by
        #3

        gmaro,

        Thanks for the ideas. To answer your question, I am trying to access my textboxes in the widget application so I can change the text.

        I am still dissecting your code though (still learning C++), so your's could solve my problem.

        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