Results 1 to 3 of 3

Thread: Unable to get access to class scope QList element

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2011
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Unable to get access to class scope QList element

    I am having difficulty getting access to a QList element at class scope. Problem is only within paintEvent. What am I missing?


    #include <QPainter>
    #include <QList>
    #include <QFrame>
    #include <QRectF>

    class Frame : public QFrame
    {
    private:
    QList<QRectF> llist;

    public:
    Frame(QFrame *parent=0);

    protected:
    virtual void paintEvent(QPaintEvent *);
    void tst();
    };



    void Frame:aintEvent(QPaintEvent *pe)
    {
    char m[20];
    int size = 10;

    // if this line is commented-out, no problem
    size = llist.size(); // Crashes here
    sprintf(m,"%d",size);

    QPainter painter(this);
    painter.setPen(Qt::blue);
    painter.setFont(QFont("Arial", 30));
    //painter.drawText(rect(), Qt::AlignCenter, "Qt");
    painter.drawText(rect(), Qt::AlignCenter, m);
    //painter.drawRect(l.at(0));
    }

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Unable to get access to class scope QList element

    Compile debug version and run with debugger, post the backtrace after crash.
    Btw. if you want to display number, better use QString::number() method:
    Qt Code:
    1. void Frame:aintEvent(QPaintEvent *pe)
    2. {
    3. // if this line is commented-out, no problem
    4. int size = llist.size(); // Crashes here
    5.  
    6. QPainter painter(this);
    7. painter.setPen(Qt::blue);
    8. painter.setFont(QFont("Arial", 30));
    9. //painter.drawText(rect(), Qt::AlignCenter, "Qt");
    10. painter.drawText(rect(), Qt::AlignCenter, QString::number(size));
    11. //painter.drawRect(l.at(0));
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2011
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Unable to get access to class scope QList element

    It's always scary when you get it working, and you don't know why. Maybe running qmake again. Thanks for the advice on QString. I was only trying to get anything to display from the QList and was a test. Thanks again stampede. How do I mark solved?

Similar Threads

  1. Access DOM element from AxWidget
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2011, 16:03
  2. Does QList use copy constructor when some element append to it?
    By indomie_seleraku in forum Qt Programming
    Replies: 7
    Last Post: 17th December 2010, 19:47
  3. Replies: 4
    Last Post: 20th August 2010, 13:54
  4. Replies: 8
    Last Post: 15th July 2010, 21:42
  5. Change a QList element
    By mcrahr in forum Newbie
    Replies: 1
    Last Post: 23rd August 2009, 11:16

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.