Adding user variables to .ui file
Hi,
I have the following problem:
My GUI has a QwtPlot and I designed a program that updates the plot from time to time. I need to add a variable to the ui_XXX.h file, especially a QwtPlotCurve. So far so good, I can access this variable easily but what I want now is, that the variable is still available after re-compiling the .ui ...
Is there a way to do this ?
Thx a lot
Rene
Re: Adding user variables to .ui file
Add the variable to the class inheriting QWidget and using the ui file instead of the ui file itself.
Re: Adding user variables to .ui file
doesn't work ...
I added the qwtPlotCurve object to mainwindow.h (instead of ui_mainwindow) and initialized it in the .cpp file.
But I can't attach it to the qwtPlot object inside the ui_mainwindow.h ... there's no compilation error, but nothing is painted at all.
thx
Re: Adding user variables to .ui file
What do you mean you can't "attach it" to an object? If you have an object in ui file, you don't need any extra variables, you can (and should) use the one from the ui file. If you have a "plot" variable in Ui::Form and you have class MyPlot that inherits QWidget and uses the Ui::Form object:
Code:
public:
ui.setupUi(this);
}
private:
Ui::Form ui;
};
then just use the variable:
Code:
void MyPlot::someMethod() {
doSomethingWith(ui.plot);
}
Re: Adding user variables to .ui file
with "attach" i mean the function QwtPlotCurve->attach(QwtPlot*) to have a curve attached to the qwtPlot. Other threads then simply update the curve's data and replots the qwtPlot. As it's always the same curve that has to be updated, I want it to be initialized in either the ui_mainwindow (in the setupUI function) or in the inherited class (mainwindow.cpp/h). Because the ui file is created new whenever the GUI changes, it's a bad solution to put it in there. But putting it into the mainwindow file doesn't work.
Re: Adding user variables to .ui file
I solved my problem, sorry for bothering you guys ;-)
Stupid mistake:
I tried to attach the curve to the plot before I called ui->setupUI(), which actually just initializes the plot instance ... so attaching it to a non-iniatialized variable threw a memory exception!
thx