Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Transfer Data Between Two Forms

    General and Desktop
    transfer data between forms
    3
    3
    1782
    Loading More Posts
    • 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
      XADOOO last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • Franckynos
          Franckynos last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • First post
            Last post