Required a pointer "this" to QWidget inside a component class.
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
Code:
#include <QApplication>
#include <QMessageBox>
#include <QWidget>
////////////////////////////////////////
Q_OBJECT
public:
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[]) {
return app.exec();
}
///// ===== end of main ======
///// MyWindow //////////////////////////
MyWindow
::MyWindow(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:
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.
Re: Required a pointer "this" to QWidget inside a component class.
why not just use NULL?
Otherwise change A like
Code:
class A {
int a;
double b;
public:
A
(int _a
= 0,
double _b
= 0.0,
QWidget* parentForMsgBox
= 0);
};
...
Re: Required a pointer "this" to QWidget inside a component class.
Hello,
OK. Thanks for this advice. I usually do so providing a full code. I did think my code was too long and it would take the whole page. Also, the code was separated into several headers / source files due to a few classes / structures I have implemented. I just assumed the problem would be to trivial but I will follow this rule next time.
As to the problem, it works now. I came here because I am still a newbie programmer and I did expect the problem would be solved in a very easy way. I really should have found it by myself :/ somehow still not experienced enough to realise that extra argument would solve the problem.
Thank you.