Results 1 to 3 of 3

Thread: Can I use a spinBox to control the number of rows in a QTableWidget?

  1. #1
    Join Date
    Nov 2009
    Posts
    20
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Can I use a spinBox to control the number of rows in a QTableWidget?

    Goal:

    I am using Qt Creator 1.2.92 and am trying to use the (changed) value of a spinBox widget in my application to dynamically alter the number of rows displayed in a QTableWidget widget.

    What I have done:

    I have succeeded in mapping the spinBox valueChanged signal to the QTableWidget insertRow slot using the "Edit signals/slots" mode while editing my file test.ui, which results in the following line in ui_test.h:

    QObject::connect(spinBox, SIGNAL(valueChanged(int)), tableWidget, SLOT(insertRow(int)));

    What I would like to do:

    QObject::connect(spinBox, SIGNAL(valueChanged(int)), tableWidget, SLOT(setRowCount(int)));

    However, when I run the associated application I get the following error after changing the spinBox value:

    Object::connect: No such slot QTableWidget::setRowCount(int) in ui_test.h:137
    Object::connect: (sender name: 'spinBox')
    Object::connect: (receiver name: 'tableWidget')

    I am completely new to Qt and to the Qt Creator and have had only a little exposure to C++. Is there a way to accomplish this? Any help would be most appreciated.

    Thanks!

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can I use a spinBox to control the number of rows in a QTableWidget?

    Quote Originally Posted by wconstan View Post
    Goal:However, when I run the associated application I get the following error after changing the spinBox value:
    Object::connect: No such slot QTableWidget::setRowCount(int) in ui_test.h:137
    Object::connect: (sender name: 'spinBox')
    Object::connect: (receiver name: 'tableWidget')
    This is because setRowCount is a property interface(a normal public member function) not a slot.
    Create your own slot, and connect it with signal valueChanged of spin box. Then in your slot you can call the setRowCount().

  3. #3
    Join Date
    Nov 2009
    Posts
    20
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: Can I use a spinBox to control the number of rows in a QTableWidget?

    Thanks much for the help.

    I resolved the problem by defining the following function in my test.cpp function:

    Qt Code:
    1. void Test::setTableRows()
    2. {
    3. int rows = ui->spinBox->value();
    4. ui->tableWidget->setRowCount(rows);
    5. }
    To copy to clipboard, switch view to plain text mode 

    which is declared as a private slot in test.h:

    Qt Code:
    1. private slots:
    2. void setTableRows();
    To copy to clipboard, switch view to plain text mode 

    To get this to work using Qt Creator, I used the Edit signals/slots mode to wire the spinBox to the centralWidget, which automatically brings up a dialog to form the signal/slot mapping. In that dialog, I selected the Edit... button below the QMainWindow list of slots and added my new setTableRows() slot. I then mapped the valueChanged signal to the (newly added) setTableRows slot.

    This worked but I also would like to hear any comments on the technique. In general, is this the best way to go about it?

    Thanks!
    Last edited by wconstan; 17th November 2009 at 16:30. Reason: spelling error

Similar Threads

  1. Count the number of rows in a QTableView
    By grub87 in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2009, 16:31
  2. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 15:29
  3. QTableWidget sorting with hidden rows
    By alex140773 in forum Qt Programming
    Replies: 0
    Last Post: 8th July 2008, 12:35
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.