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
Code:
Private:
QString txtoutput;
//this holds the data that keeps on updating private slots:
void cmdOutputDialog();
MainWindow.cpp
Code:
connect(ui->buttonclicked, SIGNAL(clicked()), this, SLOT(cmdOutputDialog()));
void MainWindow::cmdOutputDialog()
{
CmdOutputDialog *dlg=new CmdOutputDialog(this);
dlg->display(txtoutput);
dlg->exec();
}
MyDialog.h
Code:
public slots:
private:
MyDialog.cpp
Code:
void MyDialog
::display(QString &text
) {
m_disp=text;
ui->textbrowser->setText(m_disp);
}
Re: passing varying qstring value to QDialog from MAINWINDOW
Code:
QString txtoutput;
//this holds the data that keeps on updating
maybe post the update code too
Re: passing varying qstring value to QDialog from MAINWINDOW
Quote:
Re: passing varying qstring value to QDialog from MAINWINDOW
Qt Code:
Code:
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
Actually I take the ffmpeg command line contents into that qstring
My code is below:
Code:
//mainwindow.h
private:
//mainwindow.cpp
QByteArray cmdoutput
= commandProcess.
readAllStandardOutput();
txtoutput.append(cmdoutput);
Re: passing varying qstring value to QDialog from MAINWINDOW
I assume that you call this once to show window:
Code:
void MainWindow::cmdOutputDialog()
{
CmdOutputDialog *dlg=new CmdOutputDialog(this);
dlg->display(txtoutput);
dlg->exec();
}
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:
Code:
txtoutput.append(cmdoutput);
not implies that string in 'dlg' will be updated, as this:
Code:
dlg->display(txtoutput);
assigns a copy of the original 'txtoutput' for display.
You need to update 'dlg' each time you receive new content:
Code:
QByteArray cmdoutput
= commandProcess.
readAllStandardOutput();
txtoutput.append(cmdoutput);
dlg->display(txtoutput);
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:
Code:
CmdOutputDialog *dlg=new CmdOutputDialog(this);
connect( this, SIGNAL(textUpdate(const QString&)), dlg, SLOT(display(const QString&)) );
dlg->display(txtoutput);
dlg->exec();
//... and then when text changes:
txtoutput.append(cmdoutput);
emit textUpdate(txtoutput);
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
Code:
emit textUpdate(txtoutput);
then how do you receive that signal in CmdOutputDialog or how do you connect it......again thnx in advance...
Re: passing varying qstring value to QDialog from MAINWINDOW
Quote:
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.
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......:)