Results 1 to 20 of 25

Thread: Problem with a color class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with a color class

    Hello, I think
    colors::colors()
    {
    ColorData Propiedades[max_colors] =// this is local (constructor) variable, not class instance Propiedades.
    {
    { 0, "black", 0, 0, 0},
    { 1, "white",255,255,255},
    { 2, "darkGray",128,128,128},
    { 3, "gray",160,160,164},
    ...
    };
    p=&Propiedades[0]; // p now points to local (ctor) variable which will be diallocated
    //right now.
    }

    int colors::getRed(int num)
    {
    ColorData *q;
    q=p; // p points to deallocated memory.
    for (int i=0;i<=max_colors;i++){// bad, must be "i < max_colors" or even "i < colors::max_colors".
    if (num==q->num) return q->R;
    q++;
    }
    return 0;
    }

  2. #2
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with a color class

    Yes, I think that I am pointing to a deallocated variable, because p takes extrange values in the debugger. But how to do it well? How to convert this local (constructor) variable to a class instance? (Think that Im newbie in Qt and C++. I programm in Fortran, visual basic, c...)

    Thanks

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.