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. Warning message 'will be initialized [-Wreorder]'
QtWS25 Last Chance

Warning message 'will be initialized [-Wreorder]'

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.6k 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.
  • K Offline
    K Offline
    Kycho
    wrote on 15 Dec 2018, 02:28 last edited by Kycho
    #1

    Warning message

    room.cpp:1: In file included from ..\room.cpp:1:0:
    room.h:-1: In constructor 'Room::Room(const QString&, const QString&, const QString&, int, QWidget*)':
    room.h:28: warning: 'Room::roomId' will be initialized after [-Wreorder]
         const QString roomId;
                       ^
    room.h:26: warning:   'QString Room::sleepPrice' [-Wreorder]
         QString sleepPrice;
                 ^
    room.cpp:12: warning:   when initialized here [-Wreorder]
     Room::Room(const QString &_roomId , const QString &_takePrice ,
     ^
    

    My source generates the above warning message.
    It works well.
    Why is that message coming up?
    How do I resolve it?

    room.h file

    #ifndef ROOMBUTTON_H
    #define ROOMBUTTON_H
    #include <QPushButton>
    
    class Room : public QPushButton
    {
        Q_OBJECT
    public:
        explicit Room(const QString &_roomId , QWidget *parent = nullptr);
        explicit Room(const QString &_roomId , const QString &_takePrice ,
                      const QString &_sleepPrice , int _sellType , QWidget *parent = nullptr);
        static int count;
        enum{
            emptyRoom = 0,
            usingRoom = 1,
            cleaningRoom =2
        };
        enum{
            take_sleepRoom = 0,
            takeRoom = 1,
            sleepRoom = 2
        };
    
    private:
        void setWidgetProperties();
        QString sleepPrice;
        QString takePrice;
        const QString roomId;
        int sellType;
    
    private slots:
        void roomClicked();
    
    signals:
        void getId(const QString &num);
        void getSleepPrice(QString &price);
        void getTakePrice(QString &price);
    };
    
    #endif // ROOMBUTTON_H
    
    

    room.cpp file

    #include "room.h"
    #include <QDebug>
    
    Room::Room(const QString &_roomId,QWidget *parent) :
        QPushButton(parent) ,
        roomId(_roomId)
    {
        setWidgetProperties();
        ++count;
    }
    
    Room::Room(const QString &_roomId , const QString &_takePrice ,
               const QString &_sleepPrice , int _sellType , QWidget *parent):
        QPushButton (parent),
        roomId(_roomId),
        sleepPrice(_sleepPrice),
        takePrice (_takePrice),
        sellType (_sellType)
    {
        setWidgetProperties();
        ++count;
    }
    
    int Room::count = -1;
    
    void Room::setWidgetProperties()
    {
        this->setText(roomId);
        QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
        this->setSizePolicy(sizePolicy2);
        QFont font = this->font();
        font.setPointSize(24);
        this->setFont(font);
        connect(this,&QPushButton::clicked,this,&Room::roomClicked);
    }
    
    
    // SLOT
    void Room::roomClicked()
    {
        emit getId(roomId);
        emit getSleepPrice(sleepPrice);
        emit getTakePrice(takePrice);
    }
    
    

    I thank you in advance for your advice.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on 15 Dec 2018, 02:45 last edited by
      #2

      Hi,

      This warning simply say that you must initialize your variables in the same order that they are declared.

      1 Reply Last reply
      2

      2/2

      15 Dec 2018, 02:45

      • Login

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