Results 1 to 7 of 7

Thread: QListWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QListWidget

    I have few forms created in a project.
    I declared an item-based list widget as below:
    Qt Code:
    1. QListWidget *messageList;
    To copy to clipboard, switch view to plain text mode 

    in my first form's *.h file. I want
    to use it in the other forms as well. How can I call messageList and its items in another form?
    Definition of messageList in *.cpp:

    Qt Code:
    1. dock = new QDockWidget(tr("Message"), this);
    2. messageList = new QListWidget(dock);
    3. messageList->clear();
    4. messageList->addItems(QStringList()
    5. << "Hello! ");
    6. dock->setWidget(messageList);
    To copy to clipboard, switch view to plain text mode 
    Last edited by babygal; 30th August 2010 at 05:24.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget

    You will need the pointer to the listwidget..
    make some get function which will return the list widget and can be called from other forms..

  3. #3
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    Quote Originally Posted by aamer4yu View Post
    You will need the pointer to the listwidget..
    make some get function which will return the list widget and can be called from other forms..




    Any sample code?
    Last edited by babygal; 30th August 2010 at 06:44.

  4. #4
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    Any help or examples.please.

  5. #5
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: QListWidget

    The following, added to your header file, would do what it sounds like you want:
    Qt Code:
    1. public:
    2. QListWidget * getListWidgetPointer() { return messageList; }
    To copy to clipboard, switch view to plain text mode 

    I don't say that this is a good idea though. It's better to define an API for your QListWidget rather than return a pointer to it, in my opinion.

  6. #6
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    can elaborate more?

    S.O.S
    Last edited by babygal; 1st September 2010 at 07:38.

  7. #7
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    This should help you out more : http://en.wikipedia.org/wiki/Abstrac...ter_science%29

    Your messagelist belongs to a class ( a dialog ). The class accesses this messagelist through a pointer or variable that is a member of this class.

    Other objects or functions cannot access this messagelist. It would be a bad practice to let any object have access to all members of any other class. But if it is required for some good reason, you can write a member function to let other classes know what the memory location (pointer) of your messagelist is, so they can use it anyway.

    This should suffice. If not, I suggest reading any book on C++.

    Best regards,
    Marc

Similar Threads

  1. QListWidget
    By bismitapadhy in forum Qt Programming
    Replies: 17
    Last Post: 22nd March 2010, 11:44
  2. QListWidget with STL
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2007, 16:16
  3. QListWidget help please
    By munna in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2006, 12:16
  4. Another QListWidget bug?
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2006, 13:40
  5. Possible bug of Qt on QListWidget?
    By SkripT in forum Qt Programming
    Replies: 9
    Last Post: 28th March 2006, 13:05

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.