A
Alex M.
Hi, here's my code, it's a simple widget with Qt. 
[main.cpp]
_________
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget W(250,200);
return a.exec();
}
_________
[widget.h]
_________
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QTextEdit>
class Widget : public QWidget{
private:
QTextEdit *t;
public slots:
void clearText(QTextEdit *t);
public:
Widget(int, int);
};
class widget : public QWidget{
public:
QPushButton *b;
QLabel *l;
widget(Widget *parent);
};
#endif // WIDGET_H
_________
[widget.cpp]
_________
#include <widget.h>
#include <QHBoxLayout>
#include <QVBoxLayout>
Widget::Widget(int a, int b){
widget *w = new widget(this);
t = new QTextEdit(this);
QVBoxLayout *qv = new QVBoxLayout;
qv->addWidget(t);
qv->addWidget(w);
connect(w->b, SIGNAL(clicked()), t, SLOT(clearText(t))); //
clears the content of t
connect(w->b, SIGNAL(clicked()), t, SLOT(setFocus())); //sets
focus to t
setLayout(qv);
setFixedSize(a, b);
setWindowTitle("QuickTweet");
show();
};
void Widget::clearText(QTextEdit *t){
t->clear();
}
widget::widget(Widget *parent){
b = new QPushButton(tr("Clear"), this);
l = new QLabel(tr("160 characters remaining"));
QHBoxLayout *ql = new QHBoxLayout;
ql->addWidget(l);
ql->addWidget(b);
setLayout(ql);
show();
};
_________
When I build this and press the "Clear" button the t [QTextEdit] won't
clear.
What have I done wrong?
[main.cpp]
_________
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget W(250,200);
return a.exec();
}
_________
[widget.h]
_________
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QTextEdit>
class Widget : public QWidget{
private:
QTextEdit *t;
public slots:
void clearText(QTextEdit *t);
public:
Widget(int, int);
};
class widget : public QWidget{
public:
QPushButton *b;
QLabel *l;
widget(Widget *parent);
};
#endif // WIDGET_H
_________
[widget.cpp]
_________
#include <widget.h>
#include <QHBoxLayout>
#include <QVBoxLayout>
Widget::Widget(int a, int b){
widget *w = new widget(this);
t = new QTextEdit(this);
QVBoxLayout *qv = new QVBoxLayout;
qv->addWidget(t);
qv->addWidget(w);
connect(w->b, SIGNAL(clicked()), t, SLOT(clearText(t))); //
clears the content of t
connect(w->b, SIGNAL(clicked()), t, SLOT(setFocus())); //sets
focus to t
setLayout(qv);
setFixedSize(a, b);
setWindowTitle("QuickTweet");
show();
};
void Widget::clearText(QTextEdit *t){
t->clear();
}
widget::widget(Widget *parent){
b = new QPushButton(tr("Clear"), this);
l = new QLabel(tr("160 characters remaining"));
QHBoxLayout *ql = new QHBoxLayout;
ql->addWidget(l);
ql->addWidget(b);
setLayout(ql);
show();
};
_________
When I build this and press the "Clear" button the t [QTextEdit] won't
clear.