Results 1 to 2 of 2

Thread: Declaration not working

  1. #1
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Declaration not working

    Hi All,

    I have a problem in QT Designer. And i do not have the right words to address my problem. So please apologize if i tell anything wrong.

    Qt Code:
    1. void ColorPref::High_Range()
    2. {
    3.  
    4. this->Obj_Dec();
    5. hr->setPaletteBackgroundColor(color_hr);
    6. ok->setEnabled(TRUE);
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void ColorPref::Obj_Dec()
    2. {
    3. QColor color_hr = QColorDialog::getColor(
    4. QColor(),
    5. this, "color dialog" );
    6. }
    To copy to clipboard, switch view to plain text mode 

    These are two functions. Obj_Dec() is a function that declares the QColor object.
    And I am calling it from the function High_Range();

    It gives the following error

    .ui/../ColorPref.ui.h: In member function `virtual void ColorPref::High_Range()':
    .ui/../ColorPref.ui.h:27: error: `color_hr' undeclared (first use this function).ui/../ColorPref.ui.h:27: error: (Each undeclared identifier is reported only on


    Can anyone plz tell me as to why this is happening and hence solve the error.

    Note :- Obj_Dec() is Public

    Thanks and Regards
    Kenny
    Last edited by wysota; 1st March 2007 at 10:11. Reason: missing [code] tags

  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: Declaration not working

    It doesn't have anything to do with Designer or Qt at all - it is a C++ issue. "color_hr" is a local variable - it is valid only in scope of the function it was declared in. Once the function returns, the object gets destroyed (and will be created again when you enter the function the next time). If you want to have a variable which you can reference from different methods, either make it a global variable or a member of the class (latter preferred).

Similar Threads

  1. QTextEdit::find() backward not working
    By sukanyarn in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2006, 19:33
  2. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26
  3. Connect not working
    By xgoan in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2006, 11:27
  4. Replies: 1
    Last Post: 11th June 2006, 22:25
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02

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.