![]() |
Re: Need assistance from QT programmer
Ok, here's how to read values from a terminal command (or any other process)
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: Code:
#include <QProcess> Code:
#include <QDebug> 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 |
Re: Need assistance from QT programmer
By the way, in the above example, everytime the process outputs new data, the QString is overwritten with the new data.
If you'd like to catch the entire output, then use: Code:
QString outData; |
Re: Need assistance from QT programmer
Help! I'm once again in dead end :D
I have a button on my mainwindow which opens up a dialog when pressed. This dialog has it's own header, ui and cpp -files and it does some stuff on it's own. That's working just fine. On that dialog I have one button and when it's pressed, I'd like to send message back to the mainwindow and launch function that will change stuff in mainwindow with parameter taken from the dialog and then close the dialog. No matter what I do, I can't figure out how to make that happen :( I'm a bit lost because I don't what to google for. I found some examples which makes it possible to call for function, but on those examples the function would only alter the dialog window, not the mainwindow. |
Re: Need assistance from QT programmer
I think you should make the connects in your QMainWindow class, for instance:
Code:
testDialog = new QDialog(this); 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 :D Code:
class yourDialog { |
Re: Need assistance from QT programmer
Quote:
|
Re: Need assistance from QT programmer
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. |
Re: Need assistance from QT programmer
Quote:
But what I can't reach is the button from dialog.ui so I could connect it to the slot in mainwindow.cpp In my mainwindow.h I have put this: Code:
protected: Code:
class dialog : public QDialog Code:
diagWin = new dialog(this); diagWin->ui->MyButtonName Qt Creator autofills this far: diagWin->ui But after that I cannot access anything inside the UI :( |
Re: Need assistance from QT programmer
Got it working... didn't know I had to include also the "ui_dialog.." in my mainwindow.h
:) |
Re: Need assistance from QT programmer
I thought it is better to put here my little QT question in stead of creating a hole new thread, so here it comes:
Lets say i have 10 labels named label_1,label_2, label_3.......label_10 and i would like to change the text to "something". I want something like this: for (number=1; number<=10; number++) ui->label_number->setText("something"); but i have broblem at "label_number" part, i also tried label_/number , with that way it recognises the variable but i get a different error (i also convertet number to string but then i get another differrent error :(). |
Re: Need assistance from QT programmer
Quote:
if you want to iterate over several labels, it's probably easiest to put them into some kind of container, i.e. Code:
map<int, QLabel *> Labels; |
All times are GMT. The time now is 15:07. |
vBulletin® Version 3.8.8