[SOLVED]SIGNAL/SLOT issue



  • Hi everyone,
    Today, I am stuck on a part of my code, I have no idea why. In fact this is due to a bad I/O connection, I tried to debug it but I can't manage to find my error. I have a mainwindow and Findwin is a QDialog. Here's the code:
    @void Mainwin::findinpage()
    {
    Findwin findwin(this);
    findwin.exec();
    qDebug() << "Step 1 done";
    QObject::connect(&findwin,SIGNAL(stringComplete(QString)),this,SLOT(findnow(QString)));
    }

    void Mainwin::findnow(QString text)
    {
    qDebug() << "ima in findnow and imma gonna look for " << text;
    m_tabs->currentWidget()->findChild<QWebView*>()->findText(text/,QWebPage::HighlightAllOccurrences/);
    //QWebView::findText()
    }@

    This is written is Mainwin.cpp and here is some Findwin.h

    @class Findwin : public QDialog
    {
    Q_OBJECT
    public:
    explicit Findwin(QWidget *parent = 0);

    signals:
    void stringComplete(QString);

    public slots:
    void emitit();

    };@

    and finally the Findwin.cpp

    @Findwin::Findwin(QWidget *parent) : QDialog(parent)
    {
    //Some layout things...
    //but is a QPushButton

    connect(but,SIGNAL(clicked()),this,SLOT(emitit()));
    connect(but,SIGNAL(clicked()),this,SLOT(close()));
    }

    void Findwin::emitit()
    {
    qDebug() << "emitting Stringcomplete with " << this->findChild<QLineEdit*>()->text();
    emit stringComplete(this->findChild<QLineEdit*>()->text());
    }
    @

    And what I get in the Qt log is

    emitting Stringcomplete with "en"
    Step 1 done

    So in fact, I never enter Mainwin::findnow even with connect(&findwin,SIGNAL(stringComplete(QString)),this,SLOT(findnow(QString))) so what am I supposed to do?

    Thank you very much for every answer you bring



  • Try connecting your signal before calling EXEC method from the findwin class. In your Mainwin::findinpage() function.

    Basically change that function to this:
    @void Mainwin::findinpage()
    {
    Findwin findwin(this);
    QObject::connect(&findwin,SIGNAL(stringComplete(QString)),this,SLOT(findnow(QString)));

    findwin.exec(&#41;;
    qDebug(&#41; << "Step 1 done";    
    

    }
    @

    As far as I know EXEC, will stop the main loop, and won't connect the signal

    I'm not even sure, whether you need QObject namespace before connect, it depends how you defined the Mainwin class



  • Ok thank you so much it works. You should be a pro to know such things like that ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.