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:

Qt Code:
  1. ItemAdd item;
  2. 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:
Qt Code:
  1. #include "itemadd.h"
  2.  
  3. ItemAdd::ItemAdd(QWidget *parent) :
  4. QWidget(parent)
  5. {
  6. QUiLoader builder;
  7. QFile file("form.ui");
  8. file.open(QFile::ReadOnly);
  9. QWidget *myWidget = builder.load(&file, this);
  10. file.close();
  11.  
  12. QPushButton *tmpButton = new QPushButton;
  13. tmpButton = qFindChild<QPushButton*>(this,"addNewItemButton");
  14. QVBoxLayout *layout = new QVBoxLayout;
  15. layout->addWidget(myWidget);
  16. setLayout(layout);
  17. // connect(tmpButton,SIGNAL(clicked()),this,SLOT(slotAddItem()));
  18. }
  19. void ItemAdd::slotAddItem() {
  20. // Code to be added later;
  21. }
  22.  
  23. ItemAdd::~ItemAdd() {
  24.  
  25. }
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:

Qt Code:
  1. #ifndef ITEMADD_H
  2. #define ITEMADD_H
  3. #include <QtUiTools>
  4. #include <QtGui>
  5. #include <QWidget>
  6.  
  7. namespace Ui {
  8. class ItemAdd;
  9. }
  10.  
  11. class ItemAdd : public QWidget
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. explicit ItemAdd(QWidget *parent = 0);
  17. ~ItemAdd();
  18. void slotAddItem();
  19. QString uifile;
  20.  
  21. private:
  22. Ui::ItemAdd *ui;
  23. };
  24.  
  25. #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.