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+= widgets
HEADERS += \
mainwindow.h
SOURCES += \
main.cpp
QT+= widgets
HEADERS += \
mainwindow.h
SOURCES += \
main.cpp
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= nullptr
);
void getState();
signals:
public slots:
private:
Qt::WindowState m_state;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
void getState();
signals:
public slots:
private:
Qt::WindowState m_state;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "mainwindow.h"
{
resize(400,400);
}
void MainWindow::getState()
{
m_state = windowState();
}
int main(int argc, char *argv[])
{
MainWindow window;
window.show();
return app.exec();
}
#include <QApplication>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
resize(400,400);
}
void MainWindow::getState()
{
m_state = windowState();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
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)
Bookmarks