[Qt-interest] accessing custom widget properties from layout via casting

Mladen Drmac drmac.mladen at gmail.com
Thu Dec 17 22:39:35 CET 2009


Hello everyone,
I need some advice on a project that I'm working on.

I have a window with scrollarea and empty QWidget that serves as a container
for that scrollarea.
Inside container there is a QVBoxLayout.
I'm dynamically adding my custom widgets (consisted of QLabel and
QPushButton)  on this layout (as a response to signal from network).

I need to access these custom widgets from another window.
This is what I did (from mainWindow.cpp):
   temp = (UserEntryWidget *)userListWindow->getLayout()->itemAt(0);
   temp->checkUserName(query);

This is the function being called:
bool UserEntryWidget::checkUserName(QString query) {
        return userName->text() == query;
}

When debugger comes to userName->text(), it takes me to this line in
QLabel.h:
  Q_DECLARE_PRIVATE(QLabel) (this is line 159)

If i do something like this, everything works ok:
 UserEntryWidget temp = new UserEntryWidget(this,new User());
 bool deleteme = temp ->checkUserName("User");

In both cases I am creating a pointer to my Widget, so I really can't tell
what is wrong here. It may be the casting, but I don't know some other way
to do this.
Is this the right way to access objects from layout?

I would really appriciate if some of you could give me some directions about
this.

Thanks in advance,
Mladen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091217/b837ef14/attachment.html 


More information about the Qt-interest-old mailing list