Not sure why, but the QTextEdit textChanged() signal seems to be happening infinitely many times for me..is there some caveat to using this signal I didn't see in the docs somewhere?
Basically I'm just trying to implement a poor man's terminal. It works, but the printf's I've thrown in along the way get printed many many times..the way I want to implement the terminal is like this: when text is changed in the terminal, it signals the textChanged signal, which is connected to the getCommand slot. getCommand sends the command to the serialComms method, which does some processing, then emits the serial signal with the processed output string as its parameter. finally, the output string is printed on the terminal. I'm pretty sure I went overboard on the signal generation, but this should still work, according to my research on QTextEdit
my code is very messy and spread out across many files, so sorry if there's any confusion.
ctor of the class that holds the 'terminal':
terminal -> setText(">>");
terminal -> setReadOnly(FALSE);
connect(terminal, SIGNAL(textChanged()), this, SLOT(getCommand()));
terminal = new QTextEdit();
terminal -> setText(">>");
terminal -> setReadOnly(FALSE);
connect(terminal, SIGNAL(textChanged()), this, SLOT(getCommand()));
To copy to clipboard, switch view to plain text mode
method for getting command from QTextEdit:
void advancedTab::getCommand() {
QString text
= terminal
-> toPlainText
();
char *message = ba.data();
printf("emitting signal inputComm.\n");
emit inputComm(message);
}
void advancedTab::getCommand() {
QString text = terminal -> toPlainText();
QByteArray ba = text.toLocal8Bit();
char *message = ba.data();
printf("emitting signal inputComm.\n");
emit inputComm(message);
}
To copy to clipboard, switch view to plain text mode
method for printing out command on 'terminal':
void advancedTab::outputComm ( char* rawMessage) {
terminal -> setPlainText(rawMessage);
printf("MESSAGE GOTTEN!\n");
}
void advancedTab::outputComm ( char* rawMessage) {
QString output = QString(rawMessage);
terminal -> setPlainText(rawMessage);
printf("MESSAGE GOTTEN!\n");
}
To copy to clipboard, switch view to plain text mode
method for processing command:
QString serialComms
(char *stringy
) { //processing stuff
}
QString serialComms(char *stringy) {
//processing stuff
}
To copy to clipboard, switch view to plain text mode
main method:
//ops is an instance of some other class, in which the serialComms method lies
//advanced is an instance of the class that houses the terminal
QObject::connect (&ops,
SIGNAL(serial
(char*)), advanced,
SLOT(outputComm
(char*)));
QObject::connect(advanced,
SIGNAL(inputComm
(char*)),
&ops,
SLOT(serialComms
(char *)));
//ops is an instance of some other class, in which the serialComms method lies
//advanced is an instance of the class that houses the terminal
QObject::connect (&ops, SIGNAL(serial(char*)), advanced, SLOT(outputComm(char*)));
QObject::connect(advanced, SIGNAL(inputComm(char*)), &ops, SLOT(serialComms(char *)));
To copy to clipboard, switch view to plain text mode
note: this happened before to me, when I was just trying out a simple example with QTextEdit. This is why I think I may be missing some obvious detail about textChanged().
Also, when commands are typed into the terminal carefully and no key is pressed forever, which would (I think) call the signal too many times.
Bookmarks