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();
ItemAdd item;
item.show();
To copy to clipboard, switch view to plain text mode
This however doesn't seem to do anything. The contents of ItemAdd.cpp are as follows:
#include "itemadd.h"
ItemAdd
::ItemAdd(QWidget *parent
) :{
file.
open(QFile::ReadOnly);
QWidget *myWidget
= builder.
load(&file,
this);
file.close();
tmpButton = qFindChild<QPushButton*>(this,"addNewItemButton");
layout->addWidget(myWidget);
setLayout(layout);
// connect(tmpButton,SIGNAL(clicked()),this,SLOT(slotAddItem()));
}
void ItemAdd::slotAddItem() {
// Code to be added later;
}
ItemAdd::~ItemAdd() {
}
#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(slotAddItem()));
}
void ItemAdd::slotAddItem() {
// Code to be added later;
}
ItemAdd::~ItemAdd() {
}
To copy to clipboard, switch view to plain text mode
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;
}
{
Q_OBJECT
public:
explicit ItemAdd
(QWidget *parent
= 0);
~ItemAdd();
void slotAddItem();
private:
Ui::ItemAdd *ui;
};
#endif // ITEMADD_H
#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
To copy to clipboard, switch view to plain text mode
Many thanks for any help you can offer, I've looked through some documentation but can't seem to find what I need.
Bookmarks