Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.
    Last edited by JeanC; 3rd January 2008 at 15:14.

  2. #2
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    Quote Originally Posted by JeanC View Post
    <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

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    rowClicked(QModelindex)
    and
    rowClicked(const QModelIndex &)
    are not the same.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    Well I was told this in another thread:

    ---
    void QAbstractItemView:ressed( 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.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    don't define the slot as private, since other objects cant call it.
    make it public.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.

  9. #9
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    From that error you would expect something's wrong with that syntax in the connect() calls.
    removing the const and & still displays Parenthesis expected.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    it should be QModelIndex not QModelindex.

    Where is actionExit defined?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    Good spot!
    It works.!!!

    pfff, thanks a bunch.

  12. #12
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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?

  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: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

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

  14. #14
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    Thanks, I'm gonna invest this.

  15. #15
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.
    Last edited by JeanC; 4th January 2008 at 09:23.

  16. #16
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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 about the three methods you should work with.
    You have links to examples the text is referring to in the text.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  17. The following user says thank you to high_flyer for this useful post:

    JeanC (4th January 2008)

  18. #17
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.

    Quote Originally Posted by jacek View Post
    Connect to QItemSelectionModel::currentRowChanged() signal instead (you can ask QTableView for a pointer to that model's instance).

  19. #18
    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: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    Quote Originally Posted by JeanC View Post
    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).

  20. #19
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.

    Quote Originally Posted by jacek View Post
    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).

  21. #20
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::connect: No such slot MainWindowImpl::rowClicked(QModelindex)

    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.

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Replies: 2
    Last Post: 8th October 2007, 15:02
  3. Signal / Slot with specific argument and threads
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 14th September 2007, 23:43
  4. Example HowTo create custom view
    By dexjam in forum Newbie
    Replies: 6
    Last Post: 12th July 2006, 11:06
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.