BrainStorm
2nd August 2010, 14:52
Hi everyone, first I must say that my english is not very good, i'm still learning...
Well, I started learning QT a few weeks ago, and I'm now working on a chat project, it's very simple, "first project" style. The server uses a QListView to show online users. My "problem" is very simple, as I'd like to learn things right, and I'm being forced to use these lines of code to add and remove items (i'll paste the full class):
class UsersListView: public QListView
{
private:
QStringList userNames;
void refresh()
{
((QStringListModel*)model())->setStringList(userNames);
}
public:
UsersListView(QWidget* parent)
:QListView(parent)
{
setModel(new QStringListModel(userNames));
}
void appendUser(BSUser* user)
{
userNames << user->getNick();
refresh();
}
void removeUser(BSUser* user)
{
userNames.removeAll(user->getNick());
refresh();
}
};
Is this the right way? i really need to use my "refresh()" function to update items? and this is the right way to add and remove?
Thanks in advance.
Well, I started learning QT a few weeks ago, and I'm now working on a chat project, it's very simple, "first project" style. The server uses a QListView to show online users. My "problem" is very simple, as I'd like to learn things right, and I'm being forced to use these lines of code to add and remove items (i'll paste the full class):
class UsersListView: public QListView
{
private:
QStringList userNames;
void refresh()
{
((QStringListModel*)model())->setStringList(userNames);
}
public:
UsersListView(QWidget* parent)
:QListView(parent)
{
setModel(new QStringListModel(userNames));
}
void appendUser(BSUser* user)
{
userNames << user->getNick();
refresh();
}
void removeUser(BSUser* user)
{
userNames.removeAll(user->getNick());
refresh();
}
};
Is this the right way? i really need to use my "refresh()" function to update items? and this is the right way to add and remove?
Thanks in advance.