Results 1 to 7 of 7

Thread: Problem with show Model-View-Deleaget inside MainWindow class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    75
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    15

    Default Problem with show Model-View-Deleaget inside MainWindow class

    Hello,

    I'm trying code a Model-View-Deleage and I've one question:

    When I'm writting this code:
    Qt Code:
    1. QStandardItemModel model( 5, 2 );
    2. for( int r=0; r<5; r++ )
    3. for( int c=0; c<2; c++)
    4. {
    5. QStandardItem *item = new QStandardItem( QString("Row:%1, Column:%2").arg(r).arg(c) );
    6. if( c == 0 )
    7. for( int i=0; i<3; i++ )
    8. item->appendRow( new QStandardItem( QString("Item %1").arg(i) ) );
    9. model.setItem(r, c, item);
    10. }
    11.  
    12. QTableView *table = new QTableView;
    13. table->setModel(&model);
    14. table->show();
    To copy to clipboard, switch view to plain text mode 

    into a:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. 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:
    Qt Code:
    1. MainWindow w;
    2. w.show();
    To copy to clipboard, switch view to plain text mode 
    and the second with:
    Qt Code:
    1. QTableView *table = new QTableView;
    2. table->setModel(&model);
    3. table->show();
    To copy to clipboard, switch view to plain text mode 
    and everything is ok, but, when I write a
    Qt Code:
    1. QStandardItemModel model( 5, 2 );
    2. for( int r=0; r<5; r++ )
    3. for( int c=0; c<2; c++)
    4. {
    5. QStandardItem *item = new QStandardItem( QString("Row:%1, Column:%2").arg(r).arg(c) );
    6. if( c == 0 )
    7. for( int i=0; i<3; i++ )
    8. item->appendRow( new QStandardItem( QString("Item %1").arg(i) ) );
    9. model.setItem(r, c, item);
    10. }
    11.  
    12. QTableView *table = new QTableView;
    13. table->setModel(&model);
    14. table->show();
    To copy to clipboard, switch view to plain text mode 
    into:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    3. {
    4. ui->setupUi(this);
    5. //here!
    6.  
    7. }
    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:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QStandardItemModel model( 5, 2 );
    4. for( int r=0; r<5; r++ )
    5. for( int c=0; c<2; c++)
    6. {
    7. QStandardItem *item = new QStandardItem( QString("Row:%1, Column:%2").arg(r).arg(c) );
    8. if( c == 0 )
    9. for( int i=0; i<3; i++ )
    10. item->appendRow( new QStandardItem( QString("Item %1").arg(i) ) );
    11. model.setItem(r, c, item);
    12. }
    13.  
    14. QTableView *table = new QTableView;
    15. table->setModel(&model);
    16. table->show();
    17. }
    To copy to clipboard, switch view to plain text mode 
    I get a empty window too :/

    Thanks!
    Last edited by TomASS; 20th July 2009 at 16:12.

Similar Threads

  1. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  2. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 17:14
  3. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.