| The Following 2 Users Say Thank You to Berserk For This Useful Post: | ||
|
|
2010-10-02
, 14:14
|
|
|
Posts: 199 |
Thanked: 156 times |
Joined on May 2010
@ Holland
|
#162
|
QString outData; outData.append(myProcess.readAllStandardOutput());
| The Following 2 Users Say Thank You to Berserk For This Useful Post: | ||
|
|
2010-10-10
, 14:43
|
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#163
|


|
|
2010-10-10
, 15:56
|
|
|
Posts: 199 |
Thanked: 156 times |
Joined on May 2010
@ Holland
|
#164
|
testDialog = new QDialog(this);
connect(testDialog->testButton, SIGNAL(clicked()),
testDialog, SLOT(close()));
connect(testDialog->testButton, SIGNAL(clicked()),
this, SLOT(yourFunction()));

class yourDialog {
friend class yourMainWindow;
protected:
int parameter;
}
|
|
2010-10-10
, 17:06
|
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#165
|
I think you should make the connects in your QMainWindow class, for instance:
EDIT:Code:testDialog = new QDialog(this); connect(testDialog->testButton, SIGNAL(clicked()), testDialog, SLOT(close())); connect(testDialog->testButton, SIGNAL(clicked()), this, SLOT(yourFunction()));
About the parameter from the dialog:
I don't know if this is the right way to do it, but it should work.
You can make a variable protected, so that it's also accessible for friends. Making friends in C++, yay
Then you can access it with testDialog->parameter, where "testDialog" is an instance of the above yourDialog class.Code:class yourDialog { friend class yourMainWindow; protected: int parameter; }
|
|
2010-10-10
, 17:15
|
|
|
Posts: 1,023 |
Thanked: 4,421 times |
Joined on Feb 2010
@ Argentina
|
#166
|
|
|
2010-10-10
, 17:43
|
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#167
|
In dialog.h add this in public section:
QString getParam() { return param; }
In dialog.cpp add this to the button function:
param = "whatever qstring you want"
In Mainwindow.cpp add this after dialog->exec():
QString myParam = dialog->getParam();
Another easy way is make the dialgo button to store a config value in a .conf file. Then when you close the dialgo you can read this value usin qsettings.
protected: dialog* diagWin;
class dialog : public QDialog
{
Q_OBJECT
friend class MainWindow;
diagWin = new dialog(this); diagWin->show();
|
|
2010-10-10
, 18:38
|
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#168
|
|
|
2010-11-19
, 15:36
|
|
|
Posts: 194 |
Thanked: 266 times |
Joined on May 2010
|
#169
|
).
|
|
2010-11-19
, 15:46
|
|
|
Posts: 850 |
Thanked: 626 times |
Joined on Sep 2009
@ Vienna, Austria
|
#170
|
for (number=1; number<=10; number++)
ui->label_number->setText("something");
map<int, QLabel *> Labels;
Labels[1] = ui->label_1;
Labels[2] = ui->label_2;
for (number=1; number<=10; number++)
Labels[number]->setText("asdf");
It doesn't use system(), but it runs a process with QProcess.
You can still use system() for running processes without worrying about output.
Maybe it's possible to catch the output of system(), but I don't know how yet.
In myclass.h:
#include <QProcess> private: QProcess myProcess; void startProcess(); public slots: void readOutput();#include <QDebug> // The signal 'readyReadStandardOutput' is emitted when the process has made new data available through its standard output channel (stdout) connect(&myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput())); void myClass::startProcess() { // The process itself (starting) myProcess.start("gconftool-2 -R /apps/osso/hildon-desktop/views", QProcess::ReadOnly); } void myClass::readOutput() { // Put the output in a QString QString outData = myProcess.readAllStandardOutput(); qDebug() << outData; }Trolltech: "Closes all communication with the process and kills it."
In all cases, I recommend putting myProcess.close() in the destructor of the class. Maybe it's already closed because the parent is destroyed, but I like to be sure about this
More info: http://doc.trolltech.com/4.7-snapshot/qprocess.html
You can also change the openMode for the process, but in this case, ReadOnly is fine.
EDIT: please note when using .start()
You can use
myProcess.start(QString process, QStringList arguments, OpenMode)
or
myProcess.start(QString process and arguments, OpenMode)
If you put the processname and arguments in 1 QString, like I did in the above example, then please be aware that all arguments are separated by spaces. You need to use quotes around arguments that contain spaces, more info:
http://doc.trolltech.com/4.7-snapshot/qprocess.html
Wallpaeper - Desktop background manager (in Extras!)
Config Reader - Export all Gconf to an HTML file + compare feature (Extras-testing)
Even though these programs are available for free, I would appreciate any donations
Last edited by Berserk; 2010-10-04 at 18:52.