TomASS
20th July 2009, 14:36
Hello,
I'm trying code a Model-View-Deleage and I've one question:
When I'm writting this code:
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();
into a:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
then when application is running there are two windows. First whith:
MainWindow w;
w.show();
and the second with:
QTableView *table = new QTableView;
table->setModel(&model);
table->show();
and everything is ok, but, when I write a
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();
into:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
//here!
}
there are a empty window whith table->show() ? why?
when I'm trying put this code into button click:
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();
}
I get a empty window too :/
Thanks!
I'm trying code a Model-View-Deleage and I've one question:
When I'm writting this code:
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();
into a:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
then when application is running there are two windows. First whith:
MainWindow w;
w.show();
and the second with:
QTableView *table = new QTableView;
table->setModel(&model);
table->show();
and everything is ok, but, when I write a
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();
into:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
//here!
}
there are a empty window whith table->show() ? why?
when I'm trying put this code into button click:
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();
}
I get a empty window too :/
Thanks!