Slip Nine
26th May 2006, 08:22
I'm new to Qt and have some bare (console) c++ experience, so I expect this is some small error of mine, but for the life of me, I can't figure it out.
I can call myTextEdit->append() just fine in static code, but connecting a signal to it doesn't seem to work:
#include <QApplication>
#include <QObject>
#include <QWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QVBoxLayout>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget* window = new QWidget;
QPushButton* aButton = new QPushButton("A Button");
QTextEdit* aTextEdit = new QTextEdit();
QTextDocument* aDocument = new QTextDocument("Text");
aButton->setFont(QFont("Impact", 18, QFont::Bold));
aButton->setGeometry(10, 40, 180, 40);
aTextEdit->setDocument(aDocument);
aTextEdit->append("\nSome more text");
QObject::connect(aButton, SIGNAL(clicked()), aTextEdit, SLOT(append("\nSome Dynamic Text")));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(aTextEdit);
layout->addWidget(aButton);
window->resize(300, 300);
window->setLayout(layout);
window->show();
return app.exec();
}
Other slots I connect to seem to work fine (Such as clear(), cut(), paste(), etc.) but append(), setPlainText(), etc... basically anything that would achieve what I want, doesn't do anything. I've tried these commands on the QDocument the QTextEdit contains as well-- both automatic and self-created. I've tried using QStrings and blocks of static test for the append() function (Both work fine in static code) and still no luck.
I hate to think that this could be a result of my relative newness to c++, but the other slots work, so I don't think that's it...
Appending QListWidgets seems to have the same problem, but I haven't done extensive testing.
I can call myTextEdit->append() just fine in static code, but connecting a signal to it doesn't seem to work:
#include <QApplication>
#include <QObject>
#include <QWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QVBoxLayout>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget* window = new QWidget;
QPushButton* aButton = new QPushButton("A Button");
QTextEdit* aTextEdit = new QTextEdit();
QTextDocument* aDocument = new QTextDocument("Text");
aButton->setFont(QFont("Impact", 18, QFont::Bold));
aButton->setGeometry(10, 40, 180, 40);
aTextEdit->setDocument(aDocument);
aTextEdit->append("\nSome more text");
QObject::connect(aButton, SIGNAL(clicked()), aTextEdit, SLOT(append("\nSome Dynamic Text")));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(aTextEdit);
layout->addWidget(aButton);
window->resize(300, 300);
window->setLayout(layout);
window->show();
return app.exec();
}
Other slots I connect to seem to work fine (Such as clear(), cut(), paste(), etc.) but append(), setPlainText(), etc... basically anything that would achieve what I want, doesn't do anything. I've tried these commands on the QDocument the QTextEdit contains as well-- both automatic and self-created. I've tried using QStrings and blocks of static test for the append() function (Both work fine in static code) and still no luck.
I hate to think that this could be a result of my relative newness to c++, but the other slots work, so I don't think that's it...
Appending QListWidgets seems to have the same problem, but I haven't done extensive testing.