Results 1 to 3 of 3

Thread: modifying tableview outside its constructor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default modifying tableview outside its constructor

    i know this is simple but somehow i cant figure it out.

    if i have

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ....
    QTableView *myTable = new QTableView();
    myTable->setModel(model);
    QVBoxLayout *myBlayout = new QVBoxLayout();
    myBlayout->addWidget(myTable);
    ui->centralWidget->setLayout(myBlayout);
    removeRow();
    }

    void MainWindow::removeRow()
    {
    myTable->hideRow(10);

    }

    it compiles but crashes when removeRow is called, how do i access myTable outside the constructor ?
    thanks

  2. #2
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: modifying tableview outside its constructor

    took me a while to figure out but let me answer my own question,
    the Qtableview has to be declare like that: myTable = new QTableView(); and usual has to be in the header

    not too sure why, maybe someone smart can elaborate...

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: modifying tableview outside its constructor

    The pointer QTableView *myTable in the constructor goes out of scope at the end of the block. In your removeRow function, you are using the *myTable class member that is declared in the header file but never initialized. thus causing a segfault. Search the web for "variable shadowing".

Similar Threads

  1. Modifying file with Qt
    By afail in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2009, 14:34
  2. Modifying a text
    By jaca in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2008, 15:50
  3. Modifying a line in a QTextEdit
    By elcuco in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2008, 16:50
  4. Modifying Dialog problem
    By donmorr in forum Qt Tools
    Replies: 5
    Last Post: 26th May 2006, 12:56
  5. Modifying the Display on Device
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 13th April 2006, 04:36

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.