Transfer Data Between Two Forms

  • Hello!

    I have a "mainwindow" form named "program" and other form named "addstateform" which is created when I press a button on the "program" form. I want to collect the data from the "addstateform" to do stuff after this form is closed.
    I've tried following this tutorial:
    But it didn't work. I'm also new to Qt so I don't understand very well the connect function and the signals and slots.

    My code:

    • addstateform.h
      void SendData(QString text);
      void SendString();
      private slots:
      void on_Done_clicked();

    • addstateform.cpp
      void AddStateForm::on_Done_clicked()
      QString text = "HI";
      emit SendData(text);
      emit SendString();
      qDebug() << "Signal Generated";

    • program.h
      public slots:
      void GetData(QString text);
      void GetString();
      private slots:
      void on_SMAddState_clicked();

    • program.cpp
      void Program::GetData(QString text)
      qDebug() << "Text Received: " << text;
      void Program::GetString()
      qDebug() << "Signal Received";
      void Program::on_SMAddState_clicked()
      AddStateForm ast;

    I get this error in both "connect" lines:
    no matching function for call to 'Program::connect(AddStateForm&, const char[14], Program* const, const char[13])'

    I can't figure out what I'm missing/doing wrong.
    Would appreciate some help and explanation. Sorry for the long post.
    Thank you!

  • Lifetime Qt Champion


    It should be:


    You need to pass the address of your QObject to the connect function

  • This post is deleted!

Log in to reply

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