PDA

View Full Version : Help! Trying to create a ui form and use it



pmabie
20th September 2007, 18:30
Hi

I am using Qt-Win.4.3.1 Windows Vista Microsoft Visual Studio 2005

I created a ui form called finddlg and a class to go with it, when I try to access anything it cause a exception .

class QCheckBox;
class QGroupBox;
class QRadioButton;
class QPushButton;
class QComboBox;

class CFindDlg : public QWidget
{
Q_OBJECT
public:
CFindDlg(QWidget *parent);
private slots:
private:
QCheckBox *ui_cbCase;
QCheckBox *ui_cbRegex;
QCheckBox *ui_cbTrans;
QCheckBox *ui_cbWord;
QCheckBox *ui_cbWrap;
QGroupBox *ui_gbDir;
QRadioButton *ui_rbDown;
QRadioButton *ui_rbUp;
QPushButton *ui_pBCancel;
QPushButton *ui_pBFindNext;
QPushButton *ui_pBMarkAll;
QComboBox *ui_findcmbo;
};

CFindDlg::CFindDlg(QWidget *parent)
: QWidget(parent)
{

int width = 488;
int height = 162;

QUiLoader loader;
QFile file(":/forms/finddlg.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = loader.load(&file, this);
file.close();

ui_cbCase = qFindChild<QCheckBox*>(this,"cbCase");
ui_cbRegex = qFindChild<QCheckBox*>(this,"cbRegex");
ui_cbTrans= qFindChild<QCheckBox*>(this,"cbTrans");
ui_cbWord= qFindChild<QCheckBox*>(this,"cbWord");
ui_cbWrap = qFindChild<QCheckBox*>(this,"cbWrap");
ui_gbDir = qFindChild<QGroupBox*>(this,"gbDir");
ui_rbDown = qFindChild<QRadioButton*>(this,"rbDown");
ui_rbUp = qFindChild<QRadioButton*>(this,"rbUp");
ui_pBCancel = qFindChild<QPushButton*>(this,"pBCancel");
ui_pBFindNext= qFindChild<QPushButton*>(this,"pBFindNext");
ui_pBMarkAll = qFindChild<QPushButton*>(this,"pBMarkAll");
ui_findcmbo = qFindChild<QComboBox*>(this,"findcmbo");
QMetaObject::connectSlotsByName(this);

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(myWidget);
setLayout(layout);
myWidget->setBaseSize(width,height);
myWidget->setFixedSize(width,height);
myWidget->setFixedHeight(height);
myWidget->setFixedWidth(width);
myWidget->show();
myWidget->setFocus();
ui_rbDown->setChecked(true); <---- this bombs out to a declaration of the base class item declared as private
}

so my question in a nutshell is , how do I access these parts of the ui properly.

thanks for your time.
pmabie.

wysota
20th September 2007, 20:43
A quick question - why are you doing it in such a weird way? Why not compile the .ui usinc uic and do all the other regular stuff with it? The ui file is compiled into the binary anyway so there is no advantage in using the ui loader.