
Originally Posted by
Ferric
Ah, I think I understand what you mean, I need to define model and channelsView as a global pointer maybe? or something else?
Yes. I think you should declare model and channelsView as class member.
// Loader.h
class Loader {
Q_OBJECT
public:
Loader
::Loader(QWidget *parent
= 0);
// ...
private:
};
// Loader.h
class Loader {
Q_OBJECT
public:
Loader::Loader(QWidget *parent = 0);
// ...
private:
QTableView *channelsView; // pointer data member
QStandardItemModel *model;
};
To copy to clipboard, switch view to plain text mode
// Loader.cpp
: QWidget(parent
), channelsView
(0), model
(0) // initialization. {
// ....
};
void Loader::addChannelToTable() // I want this SLOT to be activated when the addButton (from the AddDialog::dialog object) is clicked.
{
this,
tr("Yes,"),
tr("It works.") );
if (!channelsView || !model) { // check whether pointers are not 0.
return;
}
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
model->setItem(row, column, item); //This item is put in the model by using the setItem(int, int, QStandardItem*) method.
}
} // I think my problem is in the line above or below.
//channelsView->setModel(model); // This is not necessary, because setModel() has been called in Loader().
// channelsView has already referred to the model.
}
// Loader.cpp
Loader::Loader(QWidget *parent)
: QWidget(parent), channelsView(0), model(0) // initialization.
{
channelsView = new QTableView(); // constraction
model = new QStandardItemModel(4,2);
// ....
};
void Loader::addChannelToTable() // I want this SLOT to be activated when the addButton (from the AddDialog::dialog object) is clicked.
{
QMessageBox::information(
this,
tr("Yes,"),
tr("It works.") );
if (!channelsView || !model) { // check whether pointers are not 0.
return;
}
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QStandardItem *item = new QStandardItem(QString("%0, %1").arg(row).arg(column));
model->setItem(row, column, item); //This item is put in the model by using the setItem(int, int, QStandardItem*) method.
}
} // I think my problem is in the line above or below.
//channelsView->setModel(model); // This is not necessary, because setModel() has been called in Loader().
// channelsView has already referred to the model.
}
To copy to clipboard, switch view to plain text mode
Bookmarks