Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]SIGNAL/SLOT issue
QtWS25 Last Chance

[SOLVED]SIGNAL/SLOT issue

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yhu420
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xcoder
      wrote on last edited by
      #2

      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

      Only a biker knows why a dog sticks his head out of a car window.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yhu420
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved