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. How to Send Data from One Ui to Another
Qt 6.11 is out! See what's new in the release blog

How to Send Data from One Ui to Another

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 297 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.
  • D Offline
    D Offline
    delivite
    wrote on last edited by
    #1

    Hi,

    I have one MainWindow and one Class; I want to send data between them using custom signal and slot. I can't seem to figure it out, I need help.

    Here is my code:
    MainWindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <iostream>
    #include "receive.h"
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    signals:
        void sendit(QString name);
    private slots:
        void on_send_button_clicked();
        void display(QString e)
        {        
         std::cout<<"Here is where I am called this "<<e.toStdString()<<std::endl;
        }
    
    private:
        Ui::MainWindow *ui;
       
    };
    #endif // MAINWINDOW_H
    

    MainWindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "receive.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);    
       Receive *r = new Receive();
       connect(this, SIGNAL(sendit(QString)), r, SLOT(display(QString)));
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    void MainWindow::on_send_button_clicked()
    {
        emit sendit(ui->lineEdit->text());
    
    }
    

    receive.h

    #ifndef RECEIVE_H
    #define RECEIVE_H
    
    #include <iostream>
    #include <QDialog>
    
    class Receive : public QDialog
    {
    public:
        Receive();
    private slots:
        void display(QString e);
    };
    
    #endif // RECEIVE_H
    

    receive.cpp

    #include "receive.h"
    #include "mainwindow.h"
    
    Receive::Receive()
    {
        
    }
    
    void Receive::display(QString e)
    {    
     std::cout<<"Here is where I am called this "<<e.toStdString()<<std::endl;
    }
    

    When I run this program, I get this message:

    06:26:29: Starting C:\Users\Troy\Documents\build-tests-Desktop_Qt_5_14_1_MinGW_32_bit-Debug\tests.exe ...
    QObject::connect: No such slot QDialog::display(QString) in ..\tests\mainwindow.cpp:11
    QObject::connect: (sender name: 'MainWindow')

    How do I get this done, please?

    Thank you for your help.

    jsulmJ 1 Reply Last reply
    0
    • D delivite

      Hi,

      I have one MainWindow and one Class; I want to send data between them using custom signal and slot. I can't seem to figure it out, I need help.

      Here is my code:
      MainWindow.h

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <iostream>
      #include "receive.h"
      QT_BEGIN_NAMESPACE
      namespace Ui { class MainWindow; }
      QT_END_NAMESPACE
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      signals:
          void sendit(QString name);
      private slots:
          void on_send_button_clicked();
          void display(QString e)
          {        
           std::cout<<"Here is where I am called this "<<e.toStdString()<<std::endl;
          }
      
      private:
          Ui::MainWindow *ui;
         
      };
      #endif // MAINWINDOW_H
      

      MainWindow.cpp

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "receive.h"
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);    
         Receive *r = new Receive();
         connect(this, SIGNAL(sendit(QString)), r, SLOT(display(QString)));
      
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      
      void MainWindow::on_send_button_clicked()
      {
          emit sendit(ui->lineEdit->text());
      
      }
      

      receive.h

      #ifndef RECEIVE_H
      #define RECEIVE_H
      
      #include <iostream>
      #include <QDialog>
      
      class Receive : public QDialog
      {
      public:
          Receive();
      private slots:
          void display(QString e);
      };
      
      #endif // RECEIVE_H
      

      receive.cpp

      #include "receive.h"
      #include "mainwindow.h"
      
      Receive::Receive()
      {
          
      }
      
      void Receive::display(QString e)
      {    
       std::cout<<"Here is where I am called this "<<e.toStdString()<<std::endl;
      }
      

      When I run this program, I get this message:

      06:26:29: Starting C:\Users\Troy\Documents\build-tests-Desktop_Qt_5_14_1_MinGW_32_bit-Debug\tests.exe ...
      QObject::connect: No such slot QDialog::display(QString) in ..\tests\mainwindow.cpp:11
      QObject::connect: (sender name: 'MainWindow')

      How do I get this done, please?

      Thank you for your help.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @delivite Make your slot public, not private

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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