The ui_editdialog.h file is generated from the .ui file Designer creates and carries this banner at the top:
/********************************************************************************
** Form generated from reading UI file 'untitled.ui'
**
** Created: Fri May 13 08:47:32 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
/********************************************************************************
** Form generated from reading UI file 'untitled.ui'
**
** Created: Fri May 13 08:47:32 2011
** by: Qt User Interface Compiler version 4.7.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
To copy to clipboard, switch view to plain text mode
So, yes... you shouldn't be editing this file.
There are three files to the typical dialog class with Designer interface. The UI file, and a class header and implementation. You write the last two (or Qt Creator creates a skeleton for you) and they use the ui_dialog.h file generated from the UI. This is what the skeleton typically looks like:
// Header
#ifndef EDITDIALOG_H
#define EDITDIALOG_H
#include <QDialog>
namespace Ui {
class EditDialog;
}
{
Q_OBJECT
public:
explicit EditDialog
(QWidget *parent
= 0);
~EditDialog();
protected:
private:
Ui::EditDialog *ui;
};
#endif // EDITDIALOG_H
// Header
#ifndef EDITDIALOG_H
#define EDITDIALOG_H
#include <QDialog>
namespace Ui {
class EditDialog;
}
class EditDialog : public QDialog
{
Q_OBJECT
public:
explicit EditDialog(QWidget *parent = 0);
~EditDialog();
protected:
void changeEvent(QEvent *e);
private:
Ui::EditDialog *ui;
};
#endif // EDITDIALOG_H
To copy to clipboard, switch view to plain text mode
// Implementation
#include "editdialog.h"
#include "ui_editdialog.h"
EditDialog
::EditDialog(QWidget *parent
) : ui(new Ui::EditDialog)
{
ui->setupUi(this);
}
EditDialog::~EditDialog()
{
delete ui;
}
void EditDialog
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
// Implementation
#include "editdialog.h"
#include "ui_editdialog.h"
EditDialog::EditDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditDialog)
{
ui->setupUi(this);
}
EditDialog::~EditDialog()
{
delete ui;
}
void EditDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
(This aggregates the UI class using a pointer but there are variations on this theme). These are the files you add slots to and use to create a new EditDialog to display to the unsuspecting world.
You can:
- Rely on QMetaObject::connectSlotsByName() (called in ui_dialog.h) to connect the actual widgets to slots by naming the slots appropriately.
- Make explicit connections between the UI and the containing class in the constructor after the setupUi() call (my preference).
- Use the Slots editor in Designer to connect the signals to slots but you need to manually add the slots to the available list.
Bookmarks