0

We have some code:

void MainWindow::textChangedListener(){
    QTextEdit* dock = qobject_cast<QTextEdit *>(QObject::sender());
    dock->setText("asd");
}

And a signal:

cout << connect(it->silaTextEdit, SIGNAL(textChanged()), this, SLOT(textChangedListener())) << endl;

which returns true (it's connected).

When I change the text of the QTextEdit - app crashes with:

First-chance exception at 0x561158D7 (Qt5Guid.dll) in asd.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00092000).
Unhandled exception at 0x561158D7 (Qt5Guid.dll) in asd.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00092000).

I try to create a TextEdit, that when user type a wrong number, I will correct it, but I can't make this working.

Thanks for any help.

Louis Langholtz
  • 2,913
  • 3
  • 17
  • 40

1 Answers1

1

you probably need to disconnect the signal, otherwise you get an infinite loop

void MainWindow::textChangedListener(){
    QTextEdit* dock = qobject_cast<QTextEdit *>(QObject::sender());
    if (dock) {
        disconnect(dock, SIGNAL(textChanged()), this, SLOT(textChangedListener()))
        dock->setText("asd");
        connect(dock, SIGNAL(textChanged()), this, SLOT(textChangedListener()))
    }
}
bibi
  • 3,671
  • 5
  • 34
  • 50