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. Transfer Data Between Two Forms

Transfer Data Between Two Forms

Scheduled Pinned Locked Moved General and Desktop
transferdatabetweenforms
3 Posts 3 Posters 2.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.
  • X Offline
    X Offline
    XADOOO
    wrote on 8 Apr 2015, 14:51 last edited by
    #1

    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:
    https://forum.qt.io/topic/19884/solved-issues-with-signals-and-slot-to-transfer-data-between-two-forms-code-included
    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
      (...)
      signals:
      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";
      this->close();
      }
      (...)

    • 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;
      ast.setModal(true);
      connect(ast,SIGNAL(SendData(QString)),this,SLOT(GetData(QString)));
      connect(ast,SIGNAL(SendString()),this,SLOT(GetString()));
      ast.exec();
      (...)

    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!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Apr 2015, 21:47 last edited by
      #2

      Hi,

      It should be:

      connect(&ast,SIGNAL(SendData(QString)),this,SLOT(GetData(QString)));
      connect(&ast,SIGNAL(SendString()),this,SLOT(GetString()));
      

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franckynos
        wrote on 13 Apr 2015, 08:36 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        3/3

        13 Apr 2015, 08:36

        • Login

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