[SOLVED] How to reuse UI from a custom dialog derived from QDialog?
-
I can create a DialogA in Qt Creator using the designer. DialogA inherits from QDialog and all is good.
What is the proper way to re-use DialogA? When I attempt to do the following DialogB does not show any user interface?
@
namespace Ui {
class DialogA ;
}class DialogA : public QDialog
{
Q_OBJECTpublic:
explicit DialogA (QWidget *parent = 0);
~DialogA ();
private:
Ui::DialogA *ui;
};
@@
#include "ui_dialoga.h"DialogA::DialogA(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogA)
{
ui->setupUi(this);
}class DialogB : public DialogA
{
Q_OBJECTpublic:
explicit DialogB (QWidget *parent = 0);
~DialogB ();
};
@@
DialogB ::DialogB ( QWidget* parent)
: DialogA ( parent)
{
}
@DialogB::exec() does not show any user interface and code following exec() is never reached.
@
DialogB* dialogB = new DialogB(this);
dialogB->exec();
@Thanks in advance,
-Ed
-
All ui creation logic if you created it is in DialogA() constructor.
Do you call DialogA() constructor from DialogB() constructor ?Also your call to exec() is not right. It should be dialogB->exec();
-
Yes, the DialogA constructor is called from DialogB constructor.
@
DialogB ::DialogB ( QWidget* parent)
: DialogA ( parent)
{
}
@This is a Qt2 project I ported to Qt4 and I am removing qt3support file-by-file.
I fixed the typo in my post:
@
dialogB->exec()
@-Ed
-
Is file "ui_dialoga.h" generated and does it contain correct setupUI() method?
If it does then you can put a breakpoint on dialogB() ctor and step into setupUi() to see if it is called or not.
[quote]DialogB::exec() does not show any user interface and code following exec() is never reached.[/quote]
How do you call this piece of code?
Is it direct call or signal/slot? -
Thank you for your help Andre. Problem solved. I made a new Qt4 project and DialogB worked fine.
The problem was the DialogB class implemented methods that override the QDialog visible property methods. This caused the dialog to not become visible and it remained hidden:
@
bool isVisible() const;
void setVisible(bool);
@These functions were intended to initialize a dialog checkbox named "visible" for the user to edit the visibility of a map layer.
Anyway, the program functioned under Qt2. However it broke porting to Qt4 help of Qt3support. I am not sure why but I will rename these methods.
Thank you very much for your patience and support,
-Ed