peterjb31
21st December 2010, 16:00
Hi all
I'm relatively new to both C++ and QT and I am trying to create an application which dynamically loads a form based on what is returned from a query to a database. Below is the code I am using to try and 'run' the form:
ItemAdd item;
item.show();
This however doesn't seem to do anything. The contents of ItemAdd.cpp are as follows:
#include "itemadd.h"
ItemAdd::ItemAdd(QWidget *parent) :
QWidget(parent)
{
QUiLoader builder;
QFile file("form.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = builder.load(&file, this);
file.close();
QPushButton *tmpButton = new QPushButton;
tmpButton = qFindChild<QPushButton*>(this,"addNewItemButton");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(myWidget);
setLayout(layout);
// connect(tmpButton,SIGNAL(clicked()),this,SLOT(slot AddItem()));
}
void ItemAdd::slotAddItem() {
// Code to be added later;
}
ItemAdd::~ItemAdd() {
}
I have based both my header and cpp file on the defaults for a QDialog form created by Qt Creator. Below is my header file:
#ifndef ITEMADD_H
#define ITEMADD_H
#include <QtUiTools>
#include <QtGui>
#include <QWidget>
namespace Ui {
class ItemAdd;
}
class ItemAdd : public QWidget
{
Q_OBJECT
public:
explicit ItemAdd(QWidget *parent = 0);
~ItemAdd();
void slotAddItem();
QString uifile;
private:
Ui::ItemAdd *ui;
};
#endif // ITEMADD_H
Many thanks for any help you can offer, I've looked through some documentation but can't seem to find what I need.
I'm relatively new to both C++ and QT and I am trying to create an application which dynamically loads a form based on what is returned from a query to a database. Below is the code I am using to try and 'run' the form:
ItemAdd item;
item.show();
This however doesn't seem to do anything. The contents of ItemAdd.cpp are as follows:
#include "itemadd.h"
ItemAdd::ItemAdd(QWidget *parent) :
QWidget(parent)
{
QUiLoader builder;
QFile file("form.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = builder.load(&file, this);
file.close();
QPushButton *tmpButton = new QPushButton;
tmpButton = qFindChild<QPushButton*>(this,"addNewItemButton");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(myWidget);
setLayout(layout);
// connect(tmpButton,SIGNAL(clicked()),this,SLOT(slot AddItem()));
}
void ItemAdd::slotAddItem() {
// Code to be added later;
}
ItemAdd::~ItemAdd() {
}
I have based both my header and cpp file on the defaults for a QDialog form created by Qt Creator. Below is my header file:
#ifndef ITEMADD_H
#define ITEMADD_H
#include <QtUiTools>
#include <QtGui>
#include <QWidget>
namespace Ui {
class ItemAdd;
}
class ItemAdd : public QWidget
{
Q_OBJECT
public:
explicit ItemAdd(QWidget *parent = 0);
~ItemAdd();
void slotAddItem();
QString uifile;
private:
Ui::ItemAdd *ui;
};
#endif // ITEMADD_H
Many thanks for any help you can offer, I've looked through some documentation but can't seem to find what I need.