Results 1 to 7 of 7

Thread: passing varying qstring value to QDialog from MAINWINDOW

  1. #1
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default passing varying qstring value to QDialog from MAINWINDOW

    Hi, m new to QT, i got a TEXTBROWSER in my MAINWINDOW which contains data that keeps on changing ...now i need to pass this changing data to my another TEXTBROWSER in QDIALOG....

    Below is my code, using which i m only able to pass the first value of data, it's not updating itself.....HELP!

    MainWindow.h
    Qt Code:
    1. Private:
    2. QString txtoutput; //this holds the data that keeps on updating
    3. private slots:
    4. void cmdOutputDialog();
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. connect(ui->buttonclicked, SIGNAL(clicked()), this, SLOT(cmdOutputDialog()));
    2.  
    3. void MainWindow::cmdOutputDialog()
    4. {
    5. CmdOutputDialog *dlg=new CmdOutputDialog(this);
    6. dlg->display(txtoutput);
    7. dlg->exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    MyDialog.h
    Qt Code:
    1. public slots:
    2. void display(QString &text);
    3. private:
    4. QString m_disp;
    To copy to clipboard, switch view to plain text mode 

    MyDialog.cpp
    Qt Code:
    1. void MyDialog::display(QString &text)
    2. {
    3. m_disp=text;
    4. ui->textbrowser->setText(m_disp);
    5. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing varying qstring value to QDialog from MAINWINDOW

    Qt Code:
    1. QString txtoutput; //this holds the data that keeps on updating
    To copy to clipboard, switch view to plain text mode 
    maybe post the update code too

  3. #3
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: passing varying qstring value to QDialog from MAINWINDOW

    Re: passing varying qstring value to QDialog from MAINWINDOW
    Qt Code:
    Qt Code:
    1. QString txtoutput; //this holds the data that keeps on updating
    To copy to clipboard, switch view to plain text mode 
    To copy to clipboard, switch view to plain text mode
    maybe post the update code too

    Actually I take the ffmpeg command line contents into that qstring

    My code is below:
    Qt Code:
    1. //mainwindow.h
    2. private:
    3. QProcess commandProcess ;
    4.  
    5. //mainwindow.cpp
    6.  
    7. QByteArray cmdoutput = commandProcess.readAllStandardOutput();
    8. txtoutput.append(cmdoutput);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing varying qstring value to QDialog from MAINWINDOW

    I assume that you call this once to show window:
    Qt Code:
    1. void MainWindow::cmdOutputDialog()
    2. {
    3. CmdOutputDialog *dlg=new CmdOutputDialog(this);
    4. dlg->display(txtoutput);
    5. dlg->exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    and you want the text to be constantly updated. To achieve this, you need to perform explicit update of the displayed text, the fact that you do:
    Qt Code:
    1. txtoutput.append(cmdoutput);
    To copy to clipboard, switch view to plain text mode 
    not implies that string in 'dlg' will be updated, as this:
    Qt Code:
    1. dlg->display(txtoutput);
    To copy to clipboard, switch view to plain text mode 
    assigns a copy of the original 'txtoutput' for display.
    You need to update 'dlg' each time you receive new content:
    Qt Code:
    1. QByteArray cmdoutput = commandProcess.readAllStandardOutput();
    2. txtoutput.append(cmdoutput);
    3. dlg->display(txtoutput);
    To copy to clipboard, switch view to plain text mode 
    So, make CmdOutputDialog object a member of your MainWindow class, or define a signal in MainWindow and connect it to 'dlg' when you create it:
    Qt Code:
    1. CmdOutputDialog *dlg=new CmdOutputDialog(this);
    2. connect( this, SIGNAL(textUpdate(const QString&)), dlg, SLOT(display(const QString&)) );
    3. dlg->display(txtoutput);
    4. dlg->exec();
    5.  
    6. //... and then when text changes:
    7.  
    8. txtoutput.append(cmdoutput);
    9. emit textUpdate(txtoutput);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: passing varying qstring value to QDialog from MAINWINDOW

    hey stampede very thanks for your reply.....

    can you tell me when we emit the signal from mainwindow as
    Qt Code:
    1. emit textUpdate(txtoutput);
    To copy to clipboard, switch view to plain text mode 
    then how do you receive that signal in CmdOutputDialog or how do you connect it......again thnx in advance...

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing varying qstring value to QDialog from MAINWINDOW

    how do you receive that signal in CmdOutputDialog or how do you connect it
    Check the last code snippet from my last post, there is a connection between signal from MainWindow and CmdOutputDialog. 'display' method is declared as a slot already, so you can have signals connected to it, only thing left to do is declare the signal in MainWindow and call 'emit'.
    Read Signals And Slots documentation to know more about this mechanism.

  7. The following user says thank you to stampede for this useful post:

    mohit_king (12th February 2011)

  8. #7
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: passing varying qstring value to QDialog from MAINWINDOW

    Hey stampede thank u very much.....its working fine now....I was stuck with this problem since many days but now it is solved all due to you........you rock......

Similar Threads

  1. Replies: 7
    Last Post: 25th July 2016, 15:42
  2. Replies: 4
    Last Post: 1st February 2010, 15:21
  3. error passing QString ?
    By vieraci in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2009, 13:10
  4. Passing Pixmaps between MainWindow and Dialog
    By ramstormrage in forum Qt Programming
    Replies: 28
    Last Post: 20th April 2008, 14:32
  5. QDialog, Mainwindow
    By triperzz in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 07:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.