Using value given in first window in third window but first window opens the second window?
-
I have this as my mainwindow.h
#include "mainwindow.h" #include<mainwindow.h> #include "ui_mainwindow.h" #include <QObject> #include <QMessageBox> #include <QProcess> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); // lists::username = "hahah"; } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_Search_clicked() { QString movie = ui->movie_name->text(); List = new lists(this); hide(); List->show(); int p = 10; qDebug()<<"emitted"; //This slot gets executed and it's effect is not remained for later!! connect(this, SIGNAL(send_d(QString)), Third, SLOT(receive(QString))); emit send_d(movie); // connect(this, SIGNAL(send(QString,int)), List, SLOT(get_movie(QString,int))); emit send(movie, p); }I have second window as follows:
#include "lists.h" #include "ui_lists.h" lists::lists(QWidget *parent) : QMainWindow(parent), ui(new Ui::lists) { ui->setupUi(this); } lists::~lists() { delete ui; } void lists::get_movie(QString m, int d) { a = m; ui->label->setText(a); num1 = d; } void lists::on_pushButton_clicked() { qDebug()<<"hello"; int num = 1; if (num==1) { Thi = new third(this); hide(); Thi->show(); } }After the pushbutton is clicked, third window is displayed. But I want to use the QString movie given in first window in the third window. My third.cpp is as follows:
#include "third.h" #include "ui_third.h" third::third(QWidget *parent) : QMainWindow(parent), ui(new Ui::third) { ui->setupUi(this); ui->label->setText(temp);//this label needs to show the movie entered in the mainwindow. } third::~third() { delete ui; } void third::receive(QString a) { temp = a;//I need movie entered in the first window }Using signals and slots like this, the effect does not last when I reach third window from second window. I know I can connect another signal from second window to the third window, but in my actual project, the signals are complex. So, I want to be able to solve in a simple program like this.
How do I get the QString 'movie' from first window to be shown in label of third.cpp without using 'connect' in second window?
As slots get executed immediately, I think I won't get the required text in label of third.ui? How do I approach this?
Thank you in advance! -
Hi,
What exactly is the goal of your GUI ?
From the looks of it might be some sort of wizard.
-
Hi,
What do you mean by "the effect does not last" ? Does the slot ever get called ?
I see that you create List before connecting the signal. Is Third initialized at the time of connecting the signal ?
I don't see why it would works with List but not with Third...