Unsolved How to Send Data from One Ui to Another
-
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.
-
@delivite Make your slot public, not private