I'm using Eclipse with Qt and even thought I wrote a simple example, it doesn't work. The small window with a button and a QLineEdit appears, but if I push the button, it writes nothing in the QLineEdit. I'm a beginner, so I don't know if I've wrote something wrong or it just doesn't work. I've tried the same example in Qt Designer, and I had the same result.
main.cpp
#include "proj.h"
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
proj w;
w.show();
return a.exec();
}
proj.h
#ifndef PROJ_H
#define PROJ_H
#include <QtGui/QWidget>
#include "ui_proj.h"
#include "testUi.h"
class proj : public QWidget
{
Q_OBJECT
public:
proj(QWidget *parent = 0);
~proj();
private:
TestUi ui;
void connection();
void scrie();
};
#endif // PROJ_H
proj.cpp
#include "proj.h"
proj::proj(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
connection();
}
proj::~proj(){}
void proj::connection(){
QObject::connect(ui.btn, SIGNAL(clicked()), this, SLOT(scrie()));
}
void proj::scrie(){
QMessageBox::information(this, "Information", ".....");
ui.ed->setText("a scris");
}
testUI.h
#include <QtGui>
#include <QApplication>
#include <qboxlayout.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qobject.h>
#include <qwidget.h>
#ifndef TESTUI_H_
#define TESTUI_H_
class TestUi{
public:
QPushButton *btn;
QLineEdit *ed;
public:
void setupUi(QWidget *w){
QHBoxLayout *lay = new QHBoxLayout;
w->setLayout(lay);
btn = new QPushButton;
ed = new QLineEdit;
lay->addWidget(btn);
lay->addWidget(ed);
}
};
#endif /* TESTUI_H_ */