Results 1 to 5 of 5

Thread: windowState() doesn't retrun the enum Qt::WindowState?

  1. #1
    Join Date
    May 2018
    Posts
    13
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default windowState() doesn't retrun the enum Qt::WindowState?

    From the documentation:

    "Qt::WindowState QWindow::windowState() const
    the screen-occupation state of the window
    See also setWindowState() and windowStates()."

    So isn't it supposed to return a Qt::WindowState?

    Well this code fails.
    .pro
    Qt Code:
    1. QT+= widgets
    2. HEADERS += \
    3. mainwindow.h
    4.  
    5. SOURCES += \
    6. main.cpp
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. class MainWindow : public QMainWindow
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit MainWindow(QWidget *parent = nullptr);
    11. void getState();
    12. signals:
    13.  
    14. public slots:
    15. private:
    16. Qt::WindowState m_state;
    17. };
    18.  
    19. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "mainwindow.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    6. {
    7. resize(400,400);
    8. }
    9.  
    10. void MainWindow::getState()
    11. {
    12. m_state = windowState();
    13. }
    14.  
    15. int main(int argc, char *argv[])
    16. {
    17. QApplication app(argc, argv);
    18. MainWindow window;
    19. window.show();
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Compiler error:

    Y:\QTProjects\Problems\myWindowState\main.cpp:12: error: C2440: '=': cannot convert from 'Qt::WindowStates' to 'Qt::WindowState'
    Y:\QTProjects\Problems\myWindowState\main.cpp:12: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    What am I missing?
    I need to be able to save m_state, and use it to setWindowState(m_state)
    Last edited by shawnlau; 7th July 2018 at 19:46.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: windowState() doesn't retrun the enum Qt::WindowState?

    The compiler doesn't lie. QWidget::windowState() returns Qt::WindowStates, not Qt::WindowState. QMainWindow is a QWidget, not a QWindow.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    shawnlau (8th July 2018)

  4. #3
    Join Date
    May 2018
    Posts
    13
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: windowState() doesn't retrun the enum Qt::WindowState?

    I see, I was looking at the documentation for the window class.

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: windowState() doesn't retrun the enum Qt::WindowState?

    Yes. So why do they call it QMainWindow instead of QMainWidget when it is actually a QWidget-based class? No wonder people have such a hard time with some parts of Qt.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #5
    Join Date
    May 2018
    Posts
    13
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: windowState() doesn't retrun the enum Qt::WindowState?

    Good point!

Similar Threads

  1. enum initialization
    By ad5xj in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2015, 21:56
  2. enum to QString
    By bibhukalyana in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2013, 09:33
  3. QT enum array
    By angarali06 in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2011, 16:21
  4. SQLQUERY - column value retrun problem
    By damodharan in forum Qt Programming
    Replies: 7
    Last Post: 27th May 2010, 08:09
  5. windowState error Qt 3.3.4
    By tt in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2006, 17:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.