ZikO
10th August 2012, 15:52
Hello,
I have recently found a problem when I wanted to use a Qt dialog window to show information or ask for a file path. The problem is that I need to do it inside a constructor of another class. If I had an arbitrary code below, what would I need put in the line 43 (inside a constructor of class A) to open QMessageBox that requires a pointer "this" to my window class? If I inherited from MyWindow, would something like &(static_cast<MyWindow&>(*this)) work?
Thanks
#include <QApplication>
#include <QMessageBox>
#include <QWidget>
////////////////////////////////////////
class MyWindow : public QWidget {
Q_OBJECT
public:
MyWindow(QWidget* parent = 0);
public slots:
signals:
};
class A {
int a;
double b;
public:
A(int _a = 0, double _b = 0.0);
};
////////////////////////////////////////
///// ===== main function ====
int main(int argc, char* argv[]) {
QApplication app(argc,argv);
return app.exec();
}
///// ===== end of main ======
///// MyWindow //////////////////////////
MyWindow::MyWindow(QWidget* parent)
: QWidget(parent) {
// Create Layout, actions, menus, etc.
A object_A(10,20.5);
}
///// End of MyWindow ///////////////////
///// A /////////////////////////////////
A::A(int _a, double _b) : a(_a), b(_b) {
// Some problems here and information need to be shown:
QMessageBox::information(
this,
tr("Title"),
tr("Information to be shown"));
}
///// End of A //////////////////////////
PS. I did not really run this code. It is only to show the problem.
I have recently found a problem when I wanted to use a Qt dialog window to show information or ask for a file path. The problem is that I need to do it inside a constructor of another class. If I had an arbitrary code below, what would I need put in the line 43 (inside a constructor of class A) to open QMessageBox that requires a pointer "this" to my window class? If I inherited from MyWindow, would something like &(static_cast<MyWindow&>(*this)) work?
Thanks
#include <QApplication>
#include <QMessageBox>
#include <QWidget>
////////////////////////////////////////
class MyWindow : public QWidget {
Q_OBJECT
public:
MyWindow(QWidget* parent = 0);
public slots:
signals:
};
class A {
int a;
double b;
public:
A(int _a = 0, double _b = 0.0);
};
////////////////////////////////////////
///// ===== main function ====
int main(int argc, char* argv[]) {
QApplication app(argc,argv);
return app.exec();
}
///// ===== end of main ======
///// MyWindow //////////////////////////
MyWindow::MyWindow(QWidget* parent)
: QWidget(parent) {
// Create Layout, actions, menus, etc.
A object_A(10,20.5);
}
///// End of MyWindow ///////////////////
///// A /////////////////////////////////
A::A(int _a, double _b) : a(_a), b(_b) {
// Some problems here and information need to be shown:
QMessageBox::information(
this,
tr("Title"),
tr("Information to be shown"));
}
///// End of A //////////////////////////
PS. I did not really run this code. It is only to show the problem.