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. Problem with function "setCentralWidget"
Qt 6.11 is out! See what's new in the release blog

Problem with function "setCentralWidget"

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 318 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.
  • C Offline
    C Offline
    Creatorczyk
    wrote on last edited by
    #1

    Hi,

    I wrote some clas named "Monitor":

    monitor.h

    class Monitor : public QGridLayout
    {
        Q_OBJECT
    public:
        Monitor(QWidget *parent = 0);
    
    public slots:
        void setValue(float value);
    };
    

    monitor.cpp

    Monitor::Monitor(QWidget *parent)
        :QGridLayout(parent)
    {
    }
    

    But when I try seet this widet in mainwindow with "setCentralWidget()" method I got some error:

    Monitor *monitor = new Monitor(this);
    setCentralWidget(monitor);
    

    Error:

    error: no matching function for call to 'MainWindow::setCentralWidget(Monitor*&)'
    no known conversion for argument 1 from 'Monitor*' to 'QWidget*'
    

    How colud I fix that?

    JonBJ 1 Reply Last reply
    0
    • C Creatorczyk

      Hi,

      I wrote some clas named "Monitor":

      monitor.h

      class Monitor : public QGridLayout
      {
          Q_OBJECT
      public:
          Monitor(QWidget *parent = 0);
      
      public slots:
          void setValue(float value);
      };
      

      monitor.cpp

      Monitor::Monitor(QWidget *parent)
          :QGridLayout(parent)
      {
      }
      

      But when I try seet this widet in mainwindow with "setCentralWidget()" method I got some error:

      Monitor *monitor = new Monitor(this);
      setCentralWidget(monitor);
      

      Error:

      error: no matching function for call to 'MainWindow::setCentralWidget(Monitor*&)'
      no known conversion for argument 1 from 'Monitor*' to 'QWidget*'
      

      How colud I fix that?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Creatorczyk said in Problem with function "setCentralWidget":

      class Monitor : public QGridLayout

      But when I try seet this widet
      no known conversion for argument 1 from 'Monitor*' to 'QWidget*'

      As the error message tells you. Your Monitor is a QLayout not a QWidget, so you can't call setCentralWidget() on it, as the name suggests.

      You could set an empty QWidget on QMainWindow::setCentralWidget(), and then set Monitor as that widget's layout, if that is what you are wanting to do. But I am unconvinced as to what you are trying to do with your Monitor: given that it is a QGridLayout, what is its setValue() intended to do, layouts/grid layouts don't have "values"?

      1 Reply Last reply
      2

      • Login

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