(Beginner) How do I summon this dialog?
-
There's a fundamental concept here I'm not grasping :(
I'm trying to create a simple address book. The "add contact" button will run the appropriate function, but I can't figure out what to put in that function in order to summon the addcontact.ui I created.
I have a feeling the answer will be long, so I appreciate in advance the time you may take to answer :)
Files I have:
ui/mainwindow.ui
ui/addcontact.ui
src/mainwindowimpl.h
src/mainwindowimpl.cpp
src/main.cppMainWindowImpl.cpp:
@#include "mainwindowimpl.h"MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
connect(actionNew_Conact, SIGNAL(activated()),
this, SLOT(addcontact()));
}
void MainWindowImpl::addcontact()
{
// this function will run when the button is pressed
// this function should summon the "add client" dialog
}@ -
if you want to 'summon' the dialog you have to:
- make a class wich handles the addcontact ui.
- include the header from your addcontact class.
- call it to show with : .exec or .show.
If you use creator for making your addcontact ui, just add a 'Qt designer form class' and you have it all at once.
edit:
if you make your ui in designer and later on add a handling class to it, you have to include the ui_addcontact.h manualy.
Look at "this":http://doc.qt.nokia.com/4.7/designer-manual.html for more info about using designer. -
I use QDevelop and the Qt Designer and included the automatically generated "ui_addcontact.h".
The class name seems to be Ui_dialogAddContact. Could you show me an example of what the function code would look like? I can't seem to get it to compile even with the inclusion.
Thank you :)
-
You really should read the link i gave you, but here is a little example:
@
#include <QApplication>
#include <QDialog>
#include "ui_dialogAddContact.h"int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Ui::dialogAddContact ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show();
return app.exec();
}
@
this will only shows your dialog, without any handling class behind it. look at your mainwindow class how to make a handling class for it. :) -
Solved!
You are a gentleman and a scholar.