[SOLVED] centering a dialog to the screen is not working
-
I am trying to center the dialog form on the screen. when i put the below code into the mainwindow.cpp file i get an error. what am i doing wrong?
@void centerWidgetOnScreen (QWidget * widget) {
QRect rect = QApplication::desktop()->availableGeometry(widget);
widget->move(rect.center() - widget->rect().center());
}@the error i get is... mainwindow.cpp:16: error: invalid use of incomplete type 'struct QDesktopWidget'
mainwindow.cpp
@#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"
#include "ui_dialog.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Dialog *q = new Dialog(this);
q->show();
}void centerWidgetOnScreen (QWidget * widget) {
QRect rect = QApplication::desktop()->availableGeometry(widget);
widget->move(rect.center() - widget->rect().center());
}MainWindow::~MainWindow()
{
delete ui;
}@ -
solved. I forget to include the desktop widget
@#include <QDesktopWidget>@