In Qt application using UI file, there are 3 approaches.
- The Direct Approach
- The Single Inheritance Approach
- The Multiple Inheritance Approach
I planned to adopt The Single Inheritance Approach for two reasons. First, Ruby Language doesn't support multiple inheritance. Second, project creation wizard of Qt Creator suggests The Single Inheritance Approach like below:
samplewidget.h
#ifndef SAMPLEWIDGET_H
#define SAMPLEWIDGET_H
#include <QtGui/QWidget>
namespace Ui
{
class SampleWidgetClass; //UI form class
}
class SampleWidget : public QWidget //top widget class
{
Q_OBJECT
public:
SampleWidget(QWidget *parent = 0);
~SampleWidget();
private:
Ui::SampleWidgetClass *ui; //instantiate UI form class
};
#endif // SAMPLEWIDGET_H
samplewidget.cpp
#include "samplewidget.h"
#include "ui_samplewidget.h"
SampleWidget::SampleWidget(QWidget *parent) //instantiate top widget class
: QWidget(parent), ui(new Ui::SampleWidgetClass)
{
ui->setupUi(this);
}
SampleWidget::~SampleWidget()
{
delete ui;
}
main.cpp
#include <QtGui/QApplication>
#include "samplewidget.h"
int main(int argc, char *argv[]) //entry point
{
QApplication a(argc, argv);
SampleWidget w;
w.show();
return a.exec();
}
Then I wrote Ruby scripts corrsponding to Qt's UI form class, top widget class and entry point.
No comments:
Post a Comment