Results 1 to 7 of 7

Thread: problem with a list of pointers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    44
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with a list of pointers

    hey, I have done a list of pointers of QWidget. Everything is well done but I want to simplify the last declaration with a for.
    My code is the following one:

    QList <QWidget*> v;
    QVector <int> v_pos(60);
    int i_sc =0;

    ONE *p1 = new ONE();
    v.insert(i_sc,p1);
    v_pos[i_sc]= SC_ONE;
    i_sc++;

    TWO *p1 = new TWO();
    v.insert(i_sc,p1);
    v_pos[i_sc]= SC_TWO;
    i_sc++;

    int i;
    QList<QWidget*> list;
    list.replace(SC_ONE,p1);
    list.replace(SC_TWO,p2);

    p1->getScreenDirectionlist(&list);
    p2->getScreenDirectionlist(&list);

    Now, I have changed
    "p1->getScreenDirectionlist(&list);" for "v.at(0)->getScreenDirectionlist(&list);"
    but It give this error Description Resource Path Location Type
    invalid conversion from `QWidget* const' to `ONE*' main.cpp tfp003 83 C/C++ Problem

    Do you know ho can i solve it?

    thanks

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem with a list of pointers

    What about foreach ?
    Qt Code:
    1. foreach (QWidget *widget, list) {
    2. ...
    3. }
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jun 2009
    Posts
    44
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with a list of pointers

    how can I use foreach?what does it do?

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem with a list of pointers

    Here is its description.
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Jun 2009
    Posts
    44
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with a list of pointers

    but is i do with a foreach,i have the same problem.
    foreach (QWidget *widget, list) {
    v.at(0)->getScreenDirectionlist(&list);
    }

    What I need is to link my pointers of the widget that I have got, with the whole list in a for. this1->getScreenDirectionlist(&list); but with a for to make shorter the code.

  6. #6
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem with a list of pointers

    No, you have to do this
    Qt Code:
    1. foreach (QWidget *widget, yourWidgetsList) {
    2. widget->getScreenDirectionlist(some_other_list);
    3. }
    To copy to clipboard, switch view to plain text mode 

    There is a little bit confusion about v and list. What are they for?
    I'm a rebel in the S.D.G.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem with a list of pointers

    Quote Originally Posted by maider View Post
    Now, I have changed
    "p1->getScreenDirectionlist(&list);" for "v.at(0)->getScreenDirectionlist(&list);"
    but It give this error Description Resource Path Location Type
    invalid conversion from `QWidget* const' to `ONE*' main.cpp tfp003 83 C/C++ Problem
    It's a pure C++ problem. The at operator delivers back a pointer to a widget as you have defined your list v! So you have to cast the pointer to your class. Use qobject_cast for that.

Similar Threads

  1. Problem with list View
    By yuvaraj.yadav in forum Qt Programming
    Replies: 9
    Last Post: 29th April 2009, 14:02
  2. Replies: 1
    Last Post: 23rd April 2009, 09:05
  3. Replies: 19
    Last Post: 3rd April 2009, 23:17
  4. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  5. K&R's strcpy function - problem with pointers
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 8th January 2006, 15: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.