Hey there,
I am having trouble with QListWidget.. When I try to add an Item to it, a segmentation fault occurs..
Hope you guys can help me out.
class PlayerWidget
: public QWidget{
Q_OBJECT
public:
public slots:
private:
short numplayer;
};
class PlayerWidget : public QWidget
{
Q_OBJECT
public:
PlayerWidget(QWidget *parent = 0);
public slots:
void newPlayer(QString);
private:
QLabel *playerLabel;
QListWidget *playerView;
short numplayer;
};
To copy to clipboard, switch view to plain text mode
PlayerWidget
::PlayerWidget(QWidget *parent
){
playerLayout->addWidget(playerLabel);
playerLayout->addWidget(playerView);
setLayout(playerLayout);
numplayer = 0;
playerView
->addItem
(QString("mooooooooo"));
// it works here!!!}
void PlayerWidget
::newPlayer(QString name
) {
//playerView->addItem(QString("name")); // not here
numplayer++;
}
PlayerWidget::PlayerWidget(QWidget *parent)
: QWidget(parent)
{
QLabel *playerLabel = new QLabel(tr("Players:"));
QListWidget *playerView = new QListWidget();
QVBoxLayout *playerLayout = new QVBoxLayout;
playerLayout->addWidget(playerLabel);
playerLayout->addWidget(playerView);
setLayout(playerLayout);
numplayer = 0;
playerView->addItem(QString("mooooooooo")); // it works here!!!
}
void PlayerWidget::newPlayer(QString name)
{
//playerView->addItem(QString("name")); // not here
new QListWidgetItem(tr("mooo"), playerView); // nor here!
numplayer++;
}
To copy to clipboard, switch view to plain text mode
newPlayer(QString) is a slot that is called by another widgets signal
Bookmarks