Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2008
Initialising and then displaying a dialog


Message 1 in thread

Thank you for reading this.

What I'm attempting to do is display a dialog that contains a table which 
accepts input from the user (me). It's all become quite complicated, so I 
hope I can explain the problem with some code snippets.

The Configuration class inherits ConfigDialog which is the dialog that I 
want to display.  ConfigDialog was generated by Designer.

MainClass inherits the Form class which is the main window dialog, also 
generated by Designer.

The following works but I know that I have not used the correct method 
because a Configuration slot is not being executed -  "slot not yet 
implemented" message is displayed.

MainClass methods and attributes:

private:
Configuration conf; // this is how I access each of the other classes from 
the main class.

private slots:
 void showDialog();

void MainClass::showDialog() // a menu item on the main window gets me to 
here
{
	conf.showDataBaseDialog();
}

class Configuration : public ConfigDialog
{
Q_OBJECT

public:
Configuration(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, 
WFlags fl = 0 );
~Configuration();

void showDataBaseDialog();
void initTable();

private:
ConfigDialog dialog;
}

void Configuration::showDataBaseDialog()
{
	dialog.exec();
}

void Configuration::initTable() // this is called from the main class before 
the dialog is displayed
{
	//this is an example of how I set up the table
	dialog.dataBaseTable->setColumnWidth( 0, 60 );
}

I've looked at lots of Qt examples but I can't relate any of the example 
code to what I'm trying to achieve. I've also tried a method the used new 
and, although I was able to display the dialog, I couldn't initialise the 
table on the dialog. I think the initialised dialog and the displayed dialog 
were not the same instance of each other.

I've spent a lot of time on this and I'm just going around in circles, so, 
any help will be greatly appreciated.

Regards,
Phil. 


--
 [ signature omitted ] 

Message 2 in thread

Hi Phil, 

Hey another aussie! That makes two of us using Qt! 

What you have seems reasonable. You have to connect the menu slot to a
QObject descendent that creates the dialog and initialises it. Normally this
would be a slot in the mainwindow. 

I am not clear why Configuration inherits from the dialog and has it as a
private member. What else does Configuration do that the dialog can't do
itself? Have a look at "Compile time form processing" in the assistant, to
see some different strategies. 

Regards, 

Tony Rietwyk


> -----Original Message-----
> From: Phil [mailto:phillor@xxxxxxxxxxx] 
> Sent: Wednesday, 6 February 2008 17:48
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Initialising and then displaying a dialog
> 
> 
> Thank you for reading this.
> 
> What I'm attempting to do is display a dialog that contains a 
> table which 
> accepts input from the user (me). It's all become quite 
> complicated, so I 
> hope I can explain the problem with some code snippets.
> 

<big snip>

> 
> Regards,
> Phil. 

--
 [ signature omitted ] 

Message 3 in thread

----- Original Message ----- 
From: "Tony Rietwyk" <tony.rietwyk@xxxxxxxxxxxxxxxx>
To: <qt-interest@xxxxxxxxxxxxx>
Sent: Wednesday, February 06, 2008 5:36 PM
Subject: RE: Initialising and then displaying a dialog


Hi Phil,

Hey another aussie! That makes two of us using Qt!

Yes Tony, but in my case purely as a means of wasting hundreds of hours
during my retirement. Thank you for taking the time to wade through my
question.

What you have seems reasonable. You have to connect the menu slot to a
QObject descendent that creates the dialog and initialises it. Normally this
would be a slot in the mainwindow.

The code that I have does work except that dialog slots aren't reached. I'm
referring to the dialog that is inherited by my Configuration class here.
The "not yet implemented" message shows that I still have a problem
somewhere. The code that is supposed to be executed is a member of the
Configuration class.

I am not clear why Configuration inherits from the dialog and has it as a
private member. What else does Configuration do that the dialog can't do
itself?

The Configuration class has a number of members one of which is initTable().
This function is called from the main window to populate the table before
the dialog is displayed, it also adds the table headers. During program
execution I want to be able to edit the contents of the table. The private
member gives me access to the table.

I understand that having Configuration inherit the dialog class (a class
generated by Designer) is normal practice. I wanted to keep the main window
class exclusively for user interfacing and have it only display the dialogs
while the other classes handle data transfer to and from the dialogs. I have
an application that does something similar to what I'm trying to do but it
is too complex for me to extract just the part that I need.

Have a look at "Compile time form processing" in the assistant, to
see some different strategies.

Qt assistant is my bible, but it's not helping in this case.

Regards,
Phil.


--
 [ signature omitted ] 

Message 4 in thread

Try this:

class MainClass : public MainWindow
{
Q_OBJECT

public:
MainClass(QWidget * parent = 0, Qt::WFlags flags = 0);
~MainClass();

private:
Configuration *conf;

private slots:
 void showDialog();
};

void MainClass::showDialog()
{
       if (conf == 0)
            conf = new Configuration(this);
       conf->showDataBaseDialog();
}

class Configuration : public ConfigDialog
{
Q_OBJECT

public:
Configuration(QWidget* parent = 0, const char* name = 0, bool modal = FALSE,
WFlags fl = 0 );
~Configuration();

void showDataBaseDialog();
void initTable();
};

void Configuration::showDataBaseDialog()
{
        exec();
}

void Configuration::initTable()
{
       dataBaseTable->setColumnWidth( 0, 60 );
}

--
 [ signature omitted ] 

Message 5 in thread

Hi,

> class Configuration : public ConfigDialog
> {
> Q_OBJECT
> 
> public:
> Configuration(QWidget* parent = 0, const char* name = 0, bool modal = 
> FALSE, WFlags fl = 0 );
> ~Configuration();
> 
> void showDataBaseDialog();
> void initTable();
> 
> private:
> ConfigDialog dialog;
> }

Why do you have both a is-a and a has-a relation between Configuration and 
ConfigDialog? Just inheriting ConfigDialog should be enough, no need to add 
the ConfigDialog private variable "dialog".

Than initialize widgets (except maybe top-level ones) using new() and 
providing a parent.

Also which version of Qt is this?

--
 [ signature omitted ]