PDA

View Full Version : Dynamically adding tabs



larry104
25th July 2006, 21:49
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.

jacek
25th July 2006, 21:59
QObject::connect()

larry104
26th July 2006, 01:24
:o

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():



class MyTableView : public QTableView
{
Q_OBJECT

public:
MyTableView(QWidget *parent = 0);

protected:

void startDrag(Qt::DropActions supportedActions);

};



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

jacek
26th July 2006, 02:05
QObject::connect(dynTab->tableView, SIGNAL(doubleClicked(QModelIndex &index)),this, SLOT(myTableView_doubleClicked(QModelIndex &index)));
http://www.qtcentre.org/forum/faq.php?faq=faq_qt_signalslot#faq_faq_qt_signalslo t_with_names


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

larry104
26th July 2006, 03:29
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?

jnana
26th July 2006, 09:16
Try with QTableWidget instead of QTableView.

wysota
26th July 2006, 10:14
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.

larry104
26th July 2006, 21:27
Yes, you are right - problem is solved. Thanks a lot.