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. Using value given in first window in third window but first window opens the second window?
Forum Updated to NodeBB v4.3 + New Features

Using value given in first window in third window but first window opens the second window?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 280 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RootLearner
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly is the goal of your GUI ?

      From the looks of it might be some sort of wizard.

      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
        Fabien-B
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0

        • Login

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