PDA

View Full Version : can't get a simple dialog working



pthomas
13th January 2006, 02:23
I was trying to make a simple dialog and use the multiple inheritance method to make it work. But I can't get it going. The dialog is called "handmade.ui". The ui_handmade.h file is being generated ok.

The latest error is:
main.cpp:29: error: 'class Ui::handmade' has no member named 'show'

I'm lost. My "handmade" dialog inherits from QDialog which inherits QWidget which contains the show() function. What gives?

Am I including things in the wrong places?

Here's my code.
main.cpp
#include "ui_handmade.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Ui::handmade *dialog = new Ui::handmade;

dialog->show(); // <- Error occurs here
return app.exec();
}

handmade.h

#ifndef HANDMADE_H
#define HANDMADE_H

#include "ui_handmade.h"

class handmade : public QDialog, private Ui::handmade
{
Q_OBJECT

public:
handmade(QWidget* parent = 0);
~handmade();
/*$PUBLIC_FUNCTIONS$*/

public slots:
/*$PUBLIC_SLOTS$*/

protected:
/*$PROTECTED_FUNCTIONS$*/

protected slots:
/*$PROTECTED_SLOTS$*/

};

#endif

handmade.cpp

#include "handmade.h"

handmade::handmade(QWidget* parent) : QDialog(parent)
{
setupUi(this);
connect(ctrSlider, SIGNAL(valueChanged()), displayLCD, SLOT(display()));
show(this);
}

handmade::~handmade()
{}

Thanks,
Paul

munna
13th January 2006, 03:41
try just show()

pthomas
13th January 2006, 04:18
Perhaps you could be more specific.

I tried:
I changed dialog->show() to show() in main.cpp, recompiled and it said show() was undefined (compile error). That one I understand.

I commented out the show() function in main.cpp and left show(this) in handmade.cpp uncommented. Compile error: handmade.cpp:29: error: no matching function for call to `handmade::show(handmade* const)

I change the function to just plain old show() in handmade.cpp, compiles fine. However, I never see the dialog box when it runs and have to kill the task. I also get a warning: main.cpp:27: warning: unused variable 'dialog'

What else am I missing?
Paul

sunil.thaha
13th January 2006, 08:29
Thomas,

The error is in main function



Ui::handmade *dialog = new Ui::handmade


instead include the handmade.h in the main and
then make object of that.
Call the show now

Also you can see the ui_handmade.h for why there is no show in the Ui::handmade

Mike
13th January 2006, 09:33
If I read your code in the main function correctly, then you're including the wrong header. You include the header that was generated by the uic compiler for your dialog resource.
However as correctly done, you created a dialog class that inherits from the uic generated class. Your class correctly inherits QDialog, and with that comes the show() method. However now it seems that you're not using your own class in the main method. Try doing this instead:



#include "handmade.h" // <-- Use your own dialog class
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Create an instance of your own dialog
handmade *dialog = new handmade;

dialog->show();
return app.exec();
}


Then your dialog should work as expected.

Ups, I think it was answered just before...

Mike
13th January 2006, 09:49
Another thing I noticed. In the constructor of your own "handmade" dialog class you invoke show(). I don't think you are suppose to do that. Normally you want to setup the dialog, set some additional stuff, maybe invoke an init method, and only then, in the calling method,
handmade->show() or for a modal dialog
handmade->exec() should be invoked. Does this make sense to you?

wysota
13th January 2006, 11:11
The latest error is:
I'm lost. My "handmade" dialog inherits from QDialog which inherits QWidget which contains the show() function. What gives?



It is the QDialog which inherits QWidget. UI::xxxx doesn't.

pthomas
13th January 2006, 14:20
I think I understand this all much better now. I tried what you guys suggested and got it working...a working dialog is such a beautiful site ;)

So my thinking was quite backwards. I was inheriting the ui_* created header file and trying to create my object with it. It now makes sense that I needed to call my extended class 'handmade.h' since IT inherits the ui_handmade.h file and QDialog.

Thanks for the help everyone,
Paul

jacek
13th January 2006, 15:52
Similar problem was discussed here (http://www.qtcentre.org/forum/showthread.php?t=34).