Results 1 to 1 of 1

Thread: C++/Qt4 - QTextEdit - textChanged slot - Question

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default C++/Qt4 - QTextEdit - textChanged slot - Question

    Hello,

    In the QTextEdit the cursor is positioned at the end of the first line of the text, as its supposed to be.
    However, if I then press the backspace key, the textChanged() slot gets called twice.
    I don't understand why. Perhaps someone could explain.
    With text and punctuation keys, the slot gets called once.
    Its not a problem for me, I'd just like to know why.
    Thanks in advance.

    Regards
    Qt Code:
    1. void menu::textButton() // slot
    2. {
    3. if (cm::subSelected == -1) {
    4. cr::message("Select an item", "Error", 2);
    5. return;
    6. }
    7. prop = new propForm(this);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void menu::editButton() // slot
    2. {
    3. prop->data->setReadOnly(false);
    4. prop->data->activateWindow();
    5. prop->data->moveCursor(QTextCursor::Start);
    6. prop->data->moveCursor(QTextCursor::EndOfBlock); //end of first line
    7. prop->data->ensureCursorVisible();
    8. QWidget *thisOne = QApplication::activeWindow();
    9. qDebug() << thisOne;
    10. qDebug() << thisOne->isTopLevel();
    11. qDebug() << thisOne->isActiveWindow();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. propForm.cpp
    2.  
    3. data = new QTextEdit(this);
    4. data->setGeometry(0, filePath->height(), this->width(), this->height() - filePath->height());
    5.  
    6. QString fileName = (cm::mainItem + "/" + cm::subItem);
    7. filePath->setText(fileName);
    8.  
    9. QFile file(fileName);
    10.  
    11. if ( ! (file.open(QIODevice::ReadWrite))) {
    12. cr::message("Can't open file.", "Error", 2);
    13. return;
    14. }
    15.  
    16. QTextStream in(&file);
    17. while ( ! in.atEnd()) data->append(in.readLine());
    18. file.close();
    19.  
    20. data->setReadOnly(true);
    21. connect (data, SIGNAL(textChanged()), this, SLOT(textChanged()));
    22. this->show();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void propForm::textChanged() // private slot
    2. {
    3. qDebug() << "text changed";
    4. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Output
    2.  
    3. menu(0x7ecc78f0)
    4. true
    5. true
    6. text changed
    7. text changed
    To copy to clipboard, switch view to plain text mode 
    Last edited by jimbo; 18th March 2015 at 13:05. Reason: Spelling

Similar Threads

  1. Replies: 4
    Last Post: 19th June 2012, 00:25
  2. QTextEdit question
    By xsaridis in forum Qt Programming
    Replies: 8
    Last Post: 6th October 2011, 17:20
  3. QTextEdit's textChanged() signal
    By bangqianchen in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2010, 10:11
  4. QTextEdit, Highlighting and textChanged()
    By onamatic in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2008, 11:44
  5. textChanged vs textEdited
    By Raccoon29 in forum Newbie
    Replies: 4
    Last Post: 27th March 2008, 17:01

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.