Results 1 to 16 of 16

Thread: A Bug in Qt?

  1. #1
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default A Bug in Qt?

    I use a QTableView and a model subclassed QAbstractTableModel to display the items which is increasing per second. And in order to display the items number which is selected by user, I use QItemSelectionModel.The attachment complete the task.But there is a strange bug.
    The selction setting of tableview is
    Qt Code:
    1. ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    2. ui.tableView->setSelectionMode(QAbstractItemView::MultiSelection);
    To copy to clipboard, switch view to plain text mode 
    And the critical codes which bring bug are
    Qt Code:
    1. QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();
    2. VerHeaderView->swapSections(1,2); //this is critial for the behavior of m_selectionModel
    To copy to clipboard, switch view to plain text mode 
    If I selected items in the tableview by push down left button of mouse,draw diagonal line of a rectangel,the release the button. The displayed number of selected items is totally wrong.

    If deleted the critical codes, repeat the selection in the same way. This time, the displayed number is right. I want to know, where is the mistake?
    Attached Files Attached Files
    Jerry

  2. #2
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    Could anyone give me a clue? Or did not I describe the problem clearly?
    Jerry

  3. #3
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    Qt Code:
    QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();

    i think you dont allocate memory field for VerHeaderView. I dont use before but i can say something.

    you try

    QHeaderView VerHeaderView(ui.tableView->horizontalHeader());

    or
    QHeaderView* VerHeaderView = new QHeaderView(ui.tableView->horizontalHeader());

    or

    QHeaderView* VerHeaderView = new QHeaderView();
    VerHeaderView = ui.tableView->horizontalHeader(); // if there is a set function, you can use

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A Bug in Qt?

    Quote Originally Posted by ascii View Post
    Qt Code:
    QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();

    i think you dont allocate memory field for VerHeaderView. I dont use before but i can say something.

    you try

    QHeaderView VerHeaderView(ui.tableView->horizontalHeader());

    or
    QHeaderView* VerHeaderView = new QHeaderView(ui.tableView->horizontalHeader());

    or

    QHeaderView* VerHeaderView = new QHeaderView();
    VerHeaderView = ui.tableView->horizontalHeader(); // if there is a set function, you can use
    you are wrong
    QHeaderView * QTableView::horizontalHeader () const
    Returns the table view's horizontal header.
    this code works perfectly
    Qt Code:
    1. QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();
    To copy to clipboard, switch view to plain text mode 
    you can investigate sources of QTableView and find that headers are created in a table.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    i had said i don't use before

  6. #6
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    er, what about my question?
    Jerry

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    cant reproduce...
    can u tell more steps in detail ?

  8. #8
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    what do u mean?The codes I attached cannot be compiled correctly or what?
    Jerry

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A Bug in Qt?

    he meant that could be nice if you post compilable project not snippet of code.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #10
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    Quote Originally Posted by spirit View Post
    he meant that could be nice if you post compilable project not snippet of code.
    My attched files is enough to get a "exe"!
    Jerry

  11. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    I meant I didnt get any errors while running the program....
    it will be nice if u cud attach some snapshots showing the prob...

  12. #12
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    I want to use the lineedit in the bottom of the window to show the row number whcih is selected by the user! But the number is not always right.If u select the row just by one mouse btn click, the number is right. If u select the rows by pushdown your left mouse btn and draw diagonal line of a rectangel,then release the button, the rows in the rectangel would be selected, but the number which is showed in the lineedit is totally wrong.
    Together with my original post, I hope I make myself clear.
    Jerry

  13. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A Bug in Qt?

    try to use something like this
    Qt Code:
    1. ...
    2. connect(ui.tableView, SIGNAL(entered(const QModelIndex &)), SLOT(entered(const QModelIndex &)));
    3.  
    4. }
    5.  
    6. void MyWidget::entered(const QModelIndex &index)
    7. {
    8. if (!index.isValid())
    9. return;
    10. ui.lineEdit->setText(QString("%1").arg(m_selectionModel->selectedRows().size()));
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  14. #14
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    it seems does not work......
    Jerry

  15. #15
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Bug in Qt?

    it seems does not work......
    And the signal does not meet the logic demand.
    Jerry

  16. #16
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A Bug in Qt?

    this code returs correct value of selected rows. maybe you do something wrong or I don't understand properly what do you want to achieve.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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.