PDA

View Full Version : Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)



JeanC
3rd January 2008, 15:04
New to qt, using qdevelop.

For a few days now I'm trying get an event working when a row is clicked in a tableview.
I think I have all the syntax right but the event is still not firing and I'm getting out of options.

In Mainwindow.ui, a signal / slot pair exists that connects the table pressed(QModelIndex) to the MainWindow.

<sender>table</sender>
<signal>pressed(QModelIndex)</signal>
<receiver>MainWindow</receiver>
<slot></slot>


Then I have this code, in mainwindowimpl.h

private slots:
void rowClicked(const QModelIndex &);

and in mainwindowimp.cpp:
in constructor:

connect(table, SIGNAL(pressed(const QModelIndex &)), this, SLOT(rowClicked(const QModelindex &)));

member function:

void MainWindowImpl::rowClicked(const QModelIndex &index)
{
int row = index.row();
QString name = model->record(row).value("name").toString();
setWindowTitle(name);
}

That event does not get called, why not? Voodoo?
Help is appreciated.

vycke
3rd January 2008, 15:10
<snip>
and in mainwindowimp.cpp:
in constructor:

connect(table, SIGNAL(pressed(const QModelIndex &)), this, SLOT(rowClicked(const QModelindex &)));



Have you tried using the signal clicked(const QModelIndex&)? I'm not sure it'll change your results, but it couldn't hurt [ pressed() is for a mouse press, clicked() for a mouse click... ymmv]

Vycke

high_flyer
3rd January 2008, 15:15
rowClicked(QModelindex)
and

rowClicked(const QModelIndex &)
are not the same.

JeanC
3rd January 2008, 15:32
Thanks folks.

@vycke
Yes i tried that, same result, nothing.

@high_flyer
I have nowhere 'rowClicked(QModelindex)' in my code, I use the designer and there it's called like that. If you open the ui file in kate yes, but that's done by the designer, isn't it.

So I'm not clear what you mean.

high_flyer
3rd January 2008, 15:39
why are you defining slots with designer if you don't use them?
Is the warning that you posted in the subject is the only one you get?

to make sure that the slot really is not being called, add a debug message, and see if it comes out in the console.
It could be that the slot is called and for some other reason you don't see the effect you expect.

JeanC
3rd January 2008, 15:57
Well I was told this in another thread:

---
void QAbstractItemView::pressed( const & index ) [signal]
as you can see signal argument type is const QModelIndex & not QModelIndex
---

I tried to drop the const and the & everywhere but no succes.
I tried qDebug() << "in callback"; but did not show up.

Thanks.

First prize goes to the person who solves this riddle.

high_flyer
3rd January 2008, 16:01
don't define the slot as private, since other objects cant call it.
make it public.

JeanC
3rd January 2008, 16:07
Done, no change.

These I get:
Object::connect: Parentheses expected, slot MainWindowImpl::
Object::connect: (sender name: 'actionExit')
Object::connect: (receiver name: 'MainWindow')
Object::connect: Parentheses expected, slot MainWindowImpl::
Object::connect: (sender name: 'table')
Object::connect: (receiver name: 'MainWindow')
Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)
Object::connect: (sender name: 'table')
Object::connect: (receiver name: 'MainWindow')

From this:
setupUi(this);
connect(actionExit, SIGNAL(triggered()), this, SLOT(exitClicked()));
connect(table, SIGNAL(clicked(const QModelIndex &)), this, SLOT(rowClicked(const QModelindex&)));

That other event, actionExit, is working though.

JeanC
3rd January 2008, 16:12
From that error you would expect something's wrong with that syntax in the connect() calls.
removing the const and & still displays Parenthesis expected.

high_flyer
3rd January 2008, 16:30
it should be QModelIndex not QModelindex.

Where is actionExit defined?

JeanC
3rd January 2008, 16:37
Good spot!
It works.!!!

pfff, thanks a bunch.

JeanC
3rd January 2008, 19:10
Now if I could have some event firing when I navigate the table with up an down keys too it would be perfect.

Now I have to click the mouse everytime to fire the event.

But there's no event relating to keys in a QTableView.

Can I do that some other way?

jacek
3rd January 2008, 20:52
Connect to QItemSelectionModel::currentRowChanged() signal instead (you can ask QTableView for a pointer to that model's instance).

JeanC
4th January 2008, 08:00
Thanks, I'm gonna invest this.

JeanC
4th January 2008, 09:15
Could you help me a bit?
I'm still very new to this and struggling.

Since there's no QItemSelectionModel signal available in designer I tried modifying the ui file. Is this the way to go?
I have put in there:

<sender>table</sender>
<signal>currentChanged(QModelIndex, QModelIndex)</signal>
<receiver>MainWindow</receiver>
<slot></slot>

Then in the contructor of MainWindowImpl:

connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changed(QModelIndex,QModelIndex)));

But changed() does not fire.
I get: QObject::connect: Cannot connect (null)::currentChanged(QModelIndex,QModelIndex) to MainWindowImpl::changed(QModelIndex,QModelIndex)

Please give me an example of how to do this, a working example is the best way to learn for me.
Thanks for your time.

high_flyer
4th January 2008, 09:22
Is this the way to go?
No, its not.
If for no other reason, then because once you change the ui again with designer you lose your changes.

Read this (http://doc.trolltech.com/4.3/designer-using-a-component.html#compile-time-form-processing)about the three methods you should work with.
You have links to examples the text is referring to in the text.

JeanC
5th January 2008, 11:33
I cannot find a relation between QTableView and QItemSelectionModel,
how is this done please.

What I think you mean is that you somehow get a pointer from the table to an instance of QItemSelectionModel?
Then what do you do with that pointer, can it be used to create a signal/slot to connect() to a callback?

Thanks.


Connect to QItemSelectionModel::currentRowChanged() signal instead (you can ask QTableView for a pointer to that model's instance).

jacek
5th January 2008, 12:42
What I think you mean is that you somehow get a pointer from the table to an instance of QItemSelectionModel?
Then what do you do with that pointer, can it be used to create a signal/slot to connect() to a callback?
You already know what to do (see post #15), just make sure you invoke selectionModel() after you have set the model (otherwise it will return a null pointer).

JeanC
5th January 2008, 13:54
Still don't get it.
I understand I have to call table->setSelectionModel(); table is the QTableView
But where is the damn QItemSelectionModel that goes in there?

No I'm not frustrated, just a bit sad.


You already know what to do (see post #15), just make sure you invoke selectionModel() after you have set the model (otherwise it will return a null pointer).

JeanC
5th January 2008, 14:15
I have
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changed(QModelIndex,QModelIndex)));

and

QItemSelection *selection = new QItemSelectionModel(model);
table->setSelectionModel(selection);

But the event does nothing. Still the null pointer.

JeanC
5th January 2008, 14:26
Got it working.
The connect() should come after selection is created.
:)

jacek
5th January 2008, 15:44
But where is the damn QItemSelectionModel that goes in there?
QTableView will create one as soon as you assign a model to it with QTableView::setModel(). Therefore you have to create the connection after a call to setModel().