Hello,
I'm trying code a Model-View-Deleage and I've one question:
When I'm writting this code:
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
if( c == 0 )
for( int i=0; i<3; i++ )
model.setItem(r, c, item);
}
table->setModel(&model);
table->show();
QStandardItemModel model( 5, 2 );
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
QStandardItem *item = new QStandardItem( QString("Row:%1, Column:%2").arg(r).arg(c) );
if( c == 0 )
for( int i=0; i<3; i++ )
item->appendRow( new QStandardItem( QString("Item %1").arg(i) ) );
model.setItem(r, c, item);
}
QTableView *table = new QTableView;
table->setModel(&model);
table->show();
To copy to clipboard, switch view to plain text mode
into a:
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
To copy to clipboard, switch view to plain text mode
then when application is running there are two windows. First whith:
MainWindow w;
w.show();
MainWindow w;
w.show();
To copy to clipboard, switch view to plain text mode
and the second with:
table->setModel(&model);
table->show();
QTableView *table = new QTableView;
table->setModel(&model);
table->show();
To copy to clipboard, switch view to plain text mode
and everything is ok, but, when I write a
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
if( c == 0 )
for( int i=0; i<3; i++ )
model.setItem(r, c, item);
}
table->setModel(&model);
table->show();
QStandardItemModel model( 5, 2 );
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
QStandardItem *item = new QStandardItem( QString("Row:%1, Column:%2").arg(r).arg(c) );
if( c == 0 )
for( int i=0; i<3; i++ )
item->appendRow( new QStandardItem( QString("Item %1").arg(i) ) );
model.setItem(r, c, item);
}
QTableView *table = new QTableView;
table->setModel(&model);
table->show();
To copy to clipboard, switch view to plain text mode
into:
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
//here!
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
//here!
}
To copy to clipboard, switch view to plain text mode
there are a empty window whith table->show() ? why?
when I'm trying put this code into button click:
void MainWindow::on_pushButton_clicked()
{
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
if( c == 0 )
for( int i=0; i<3; i++ )
model.setItem(r, c, item);
}
table->setModel(&model);
table->show();
}
void MainWindow::on_pushButton_clicked()
{
QStandardItemModel model( 5, 2 );
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
QStandardItem *item = new QStandardItem( QString("Row:%1, Column:%2").arg(r).arg(c) );
if( c == 0 )
for( int i=0; i<3; i++ )
item->appendRow( new QStandardItem( QString("Item %1").arg(i) ) );
model.setItem(r, c, item);
}
QTableView *table = new QTableView;
table->setModel(&model);
table->show();
}
To copy to clipboard, switch view to plain text mode
I get a empty window too :/
Thanks!
Bookmarks