Search code examples
c++qtsignals-slots

Connect Segmentation Fault in Qt


I am getting an error on my connect segmentation fault and program crashes. SIGSEGV

//notepad.cpp
connect(Properties->UI->okWordPushButton, SIGNAL(clicked()), this, SLOT(wordcount(int)));

void notepad::wordcount(int wcount)
{

        wcount = ui->textEdit->toPlainText().split(QRegExp("(\\s|\\n|\\r)+"), QString::SkipEmptyParts).count();
        Properties->UI->wordcountlabel->setText(QString::number(wcount))

}

What I am trying to accomplish is that when I press okWordPushButton in Properties it will read from notepad->textEdit and send an int to Properties->wordcountlabel

//notepad.h
public slots:
    void wordcount(int);

I have included all the files for properties but I get that error. Please help.


Solution

  • I had to use a different approach.

     connect(Properties, SIGNAL(wordComboChanged(int, QString)), this,SLOT(calculateWordCount(int, QString)));
    connect(this, SIGNAL(wordCountUpdated(int)), Properties, SLOT(updateWordCount(int)));