Prev: Why error?
Next: Available C++ Libraries FAQ
From: Alex M. on 1 Aug 2010 08:53 { Qt is not a commercial library, but there might be a better forum specifically targeted for Qt developers. -mod } 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? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Javi on 4 Aug 2010 04:18 > 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 > Which version of Qt are you using? I would try this: connect(w->b, SIGNAL(clicked()), t, SLOT(clear())); // clears the content of t -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: Why error? Next: Available C++ Libraries FAQ |