Results 1 to 8 of 8

Thread: Dynamically adding tabs

  1. #1
    Join Date
    Jun 2006
    Location
    San Jose, CA
    Posts
    53
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dynamically adding tabs

    Hi,

    I'm dynamically adding tabs to a QTabWidget using buttons add/delete tab. In each tab there is a QTableView. Now in each of the QTableViews there should be the possibility to double click on a row. Having only a static single tab+tableView I specified a slot for that table view "on_tableView1_doubleClicked(const QModelIndex &index);" and the code which goes along with that. How can can I do that for the dynamically created table views?

    Can someone point me into the right direction?
    Thanks.

  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: Dynamically adding tabs


  3. #3
    Join Date
    Jun 2006
    Location
    San Jose, CA
    Posts
    53
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically adding tabs



    So, when doing that:
    QObject::connect(dynTab->tableView, SIGNAL(doubleClicked(QModelIndex &index)),this, SLOT(myTableView_doubleClicked(QModelIndex &index)));

    When running it I get an error:
    Object::connect: No such signal MyTableView::doubleClicked(QModelIndex&index)
    Object::connect: (sender name: 'dynTableView')
    Object::connect: (receiver name: 'mainGui')

    I have to say the MyTableView was subclassed from QTableView so that I could reimplement startDrag():

    Qt Code:
    1. class MyTableView : public QTableView
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyTableView(QWidget *parent = 0);
    7.  
    8. protected:
    9.  
    10. void startDrag(Qt::DropActions supportedActions);
    11.  
    12. };
    To copy to clipboard, switch view to plain text mode 

    Under getting more do I need to reimplement the signal doubleClicked when subclassing?

  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: Dynamically adding tabs

    Quote Originally Posted by larry104
    QObject::connect(dynTab->tableView, SIGNAL(doubleClicked(QModelIndex &index)),this, SLOT(myTableView_doubleClicked(QModelIndex &index)));
    http://www.qtcentre.org/forum/faq.ph...lot_with_names

    do I need to reimplement the signal doubleClicked when subclassing?
    No, you don't implement signals.

  5. #5
    Join Date
    Jun 2006
    Location
    San Jose, CA
    Posts
    53
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically adding tabs

    Correcting the connect() syntax to
    QObject::connect(dynTab->tableView, SIGNAL(doubleClicked(QModelIndex &)),this, SLOT(myTableView_doubleClicked(QModelIndex &)));
    gives me the same error:
    Object::connect: No such signal MyTableView::doubleClicked(QModelIndex&)

    Strange? Anything else I might miss?

  6. #6
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamically adding tabs

    Try with QTableWidget instead of QTableView.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically adding tabs

    Quote Originally Posted by larry104
    Correcting the connect() syntax to
    QObject::connect(dynTab->tableView, SIGNAL(doubleClicked(QModelIndex &)),this, SLOT(myTableView_doubleClicked(QModelIndex &)));
    gives me the same error:
    Object::connect: No such signal MyTableView::doubleClicked(QModelIndex&)

    Strange? Anything else I might miss?
    should be "doubleClicked(const QModelIndex &)", note the "const" keyword. In both signal and slot.

  8. The following user says thank you to wysota for this useful post:

    larry104 (26th July 2006)

  9. #8
    Join Date
    Jun 2006
    Location
    San Jose, CA
    Posts
    53
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically adding tabs

    Yes, you are right - problem is solved. Thanks a lot.

Similar Threads

  1. Removing Tabs
    By NewGuy in forum Qt Programming
    Replies: 6
    Last Post: 22nd July 2006, 22:46

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.