PDA

View Full Version : QListWidget



babygal
30th August 2010, 05:15
I have few forms created in a project.
I declared an item-based list widget as below:

QListWidget *messageList;

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:


QDockWidget *dock;
dock = new QDockWidget(tr("Message"), this);
messageList = new QListWidget(dock);
messageList->clear();
messageList->addItems(QStringList()
<< "Hello! ");
dock->setWidget(messageList);

aamer4yu
30th August 2010, 05:37
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..

babygal
30th August 2010, 06:26
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?

babygal
31st August 2010, 09:03
Any help or examples.please.

Urthas
31st August 2010, 22:18
The following, added to your header file, would do what it sounds like you want:


public:
QListWidget * getListWidgetPointer() { return messageList; }


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.

babygal
1st September 2010, 07:30
can elaborate more?

S.O.S

marcvanriet
1st September 2010, 12:01
This should help you out more : http://en.wikipedia.org/wiki/Abstraction_%28computer_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