Results 1 to 13 of 13

Thread: inserting a row in a QTableWidget doesn t work!

  1. #1
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default inserting a row in a QTableWidget doesn t work!

    Hi everybody,
    i want to insert a row in QTableWidget with a buttonclick.

    Qt Code:
    1. class CoordinateTable:public QTableWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. CoordinateTable(QWidget *parent=0);
    6.  
    7. private slots :
    8. void addrow();
    9.  
    10. };
    11.  
    12.  
    13. CoordinateTable::CoordinateTable(QWidget *parent)
    14. : QTableWidget(parent)
    15. { setColumnCount(2);
    16. setRowCount(2);
    17. };
    18. void CoordinateTable::addrow()
    19. {
    20. int row = CoordinateTable::rowCount();
    21. CoordinateTable:: insertRow(row);
    22.  
    23. };
    To copy to clipboard, switch view to plain text mode 

    In main

    Qt Code:
    1. ....
    2. CoordinateTable *tableWidget = new CoordinateTable;
    3. QObject::connect(okbutton, SIGNAL(clicked()),
    4. tableWidget ,SLOT(addrow()));
    To copy to clipboard, switch view to plain text mode 
    okbutton is a QT4 QPushButton.
    Nothing happens when i click the button and i dont understand why.
    Last edited by adonis; 28th April 2007 at 10:11. Reason: spelling error

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    What happens if you add "qApp->aboutQt();" to CoordinateTable::addrow()?

  3. #3
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Hi jacek,Thanks for your reply.
    If you mean like that:
    Qt Code:
    1. void CoordinateTable::addrow()
    2. {
    3. int row = CoordinateTable::rowCount();
    4. CoordinateTable::insertRow(row);
    5. qApp->aboutQt();
    6. };
    To copy to clipboard, switch view to plain text mode 
    it doesnt work too!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Quote Originally Posted by adonis View Post
    it doesnt work too!
    Does "doesn't work" mean that the application runs, but it doesn't show the "About Qt" window when you click the button?

  5. #5
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Quote Originally Posted by jacek View Post
    Does "doesn't work" mean that the application runs, but it doesn't show the "About Qt" window when you click the button?

    Yes, that´s what i mean!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Add "CONFIG += console" to your .pro file, re-run qmake and make and see whether there are no error messages on the console.

    How do you initialize okbutton?

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: inserting a row in a QTableWidget doesn t work!

    Is the class declaration in a header file and listed in .pro?
    J-P Nurmi

  8. #8
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    I don t see any errors on the console;
    The initialization of the okbutton is:
    Qt Code:
    1. QPushButton *okbutton=new QPushButton("Ok");
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Do you add your button to a layout? Because I don't see creating it with a parent, and if you don't add it to a layout, I'm not sure any signals will work?

    Does connect says anything in the debug console?

    Regards

  10. #10
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    it works now! i ve included a .moc file(i don t really understand how this works) and now every thing is OK.

    Thank you guys!

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Quote Originally Posted by adonis View Post
    i ve included a .moc file(i don t really understand how this works) and now every thing is OK.
    That .moc file, among other things, contains the code that implements the signals and slots mechanism for your class. If you won't link your application with it, signals and slots won't work for your class. To avoid such problems in future, you should use qmake, CMake or any other build system, that understands Qt needs.

  12. #12
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Thanks jacek for the explanation.Actually ,i am using qmake.Should I use the moc file each time i want to define Signals or Slots in a class??

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inserting a row in a QTableWidget doesn t work!

    Quote Originally Posted by adonis View Post
    Actually ,i am using qmake.Should I use the moc file each time i want to define Signals or Slots in a class??
    If you use qmake, then there are two things to remember:
    • you have to re-run qmake after you add or remove Q_OBJECT macro to a class definition,
    • if a class definition with Q_OBJECT is placed in a .cpp file instead of a header file, you have to add #include "filename.moc" at the end of that file and re-run qmake.

Similar Threads

  1. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 01:10

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.