Results 1 to 6 of 6

Thread: Adding user variables to .ui file

  1. #1
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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:
    Qt Code:
    1. class MyPlot: public QWidget {
    2. public:
    3. MyPlot(QWidget *parent = 0) : QWidget(parent) {
    4. ui.setupUi(this);
    5. }
    6. private:
    7. Ui::Form ui;
    8. };
    To copy to clipboard, switch view to plain text mode 
    then just use the variable:
    Qt Code:
    1. void MyPlot::someMethod() {
    2. doSomethingWith(ui.plot);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  6. #6
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

Similar Threads

  1. Save/Load variables to FIle
    By Jordan in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2010, 11:35
  2. Automatically setting up pro.user file parameters
    By purplecoast in forum Qt Tools
    Replies: 0
    Last Post: 23rd April 2010, 19:10
  3. Replies: 1
    Last Post: 9th May 2008, 14:49
  4. Replies: 3
    Last Post: 6th February 2008, 12:53
  5. Restrict user to open the same file
    By vermarajeev in forum General Programming
    Replies: 33
    Last Post: 25th May 2007, 08:15

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.