Results 1 to 5 of 5

Thread: QTextEdit textChanged() signal occurs way too frequently

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit textChanged() signal occurs way too frequently

    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':
    Qt Code:
    1. terminal = new QTextEdit();
    2. terminal -> setText(">>");
    3. terminal -> setReadOnly(FALSE);
    4.  
    5. connect(terminal, SIGNAL(textChanged()), this, SLOT(getCommand()));
    To copy to clipboard, switch view to plain text mode 

    method for getting command from QTextEdit:
    Qt Code:
    1. void advancedTab::getCommand() {
    2. QString text = terminal -> toPlainText();
    3. QByteArray ba = text.toLocal8Bit();
    4. char *message = ba.data();
    5.  
    6.  
    7. printf("emitting signal inputComm.\n");
    8.  
    9. emit inputComm(message);
    10. }
    To copy to clipboard, switch view to plain text mode 

    method for printing out command on 'terminal':
    Qt Code:
    1. void advancedTab::outputComm ( char* rawMessage) {
    2. QString output = QString(rawMessage);
    3.  
    4. terminal -> setPlainText(rawMessage);
    5. printf("MESSAGE GOTTEN!\n");
    6. }
    To copy to clipboard, switch view to plain text mode 

    method for processing command:
    Qt Code:
    1. QString serialComms(char *stringy) {
    2. //processing stuff
    3. }
    To copy to clipboard, switch view to plain text mode 

    main method:
    Qt Code:
    1. //ops is an instance of some other class, in which the serialComms method lies
    2. //advanced is an instance of the class that houses the terminal
    3.  
    4. QObject::connect (&ops, SIGNAL(serial(char*)), advanced, SLOT(outputComm(char*)));
    5. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit textChanged() signal occurs way too frequently

    When does serial() get emitted?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    dsab123 (19th June 2012)

Similar Threads

  1. QTextEdit's textChanged() signal
    By bangqianchen in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2010, 10:11
  2. QTextEdit, Highlighting and textChanged()
    By onamatic in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2008, 11:44
  3. Subclassing QLineEdit and suppress signal textChanged
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2008, 17:40
  4. No such signal QLineEdit::textChanged(QString&)
    By zorro68 in forum Qt Programming
    Replies: 4
    Last Post: 14th November 2007, 19:35
  5. textChanged signal issue
    By chaosgeorge in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2006, 00:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.