Results 1 to 3 of 3

Thread: Easy Signal-Slot-Problem

  1. #1
    Join Date
    Feb 2010
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Easy Signal-Slot-Problem

    Hey,

    I have a small problem:

    I want to connect my QPushButtons to a Slot, which needs a int as argument, so I tried:

    QObject::connect(Level1, SIGNAL(clicked()), parent, SLOT(StartLevel(1)));
    QObject::connect(Level2, SIGNAL(clicked()), parent, SLOT(StartLevel(2)));
    QObject::connect(Level3, SIGNAL(clicked()), parent, SLOT(StartLevel(3)));

    But as an application output, I get:
    Qt Code:
    1. Object::connect: No such slot StartWindow::StartLevel(1)
    2. Object::connect: No such slot StartWindow::StartLevel(2)
    3. Object::connect: No such slot StartWindow::StartLevel(3)
    To copy to clipboard, switch view to plain text mode 

    My Slot in a QMainWindow:

    void StartWindow::StartLevel(int _level)
    {
    Level *level = new Level(_level);
    qDebug() << this->focusWidget();

    this->setCentralWidget(level);
    level->grabKeyboard();

    }


    Is there a easy way to connect the clicked()-Signal to a Slot, which needs an int-argument?

    Thanks for your answer...

    nearlyNERD

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Easy Signal-Slot-Problem

    Use QSignalMapper. You'll connect all your buttons to the mapper and give each one an Id. Then when the button is clicked, it will call your function with that Id as parameter.

  3. The following user says thank you to squidge for this useful post:

    nearlyNERD (7th March 2010)

  4. #3
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Easy Signal-Slot-Problem

    Qt Code:
    1. QObject::connect(Level1, SIGNAL(clicked()), parent, SLOT(StartLevel()))
    To copy to clipboard, switch view to plain text mode 

    The signature of a signal must match the signature of the receiving slot.

Similar Threads

  1. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 19:10
  2. Problem with New Slot/Signal in QTDesigner4.4.3
    By durgarao in forum Qt Tools
    Replies: 1
    Last Post: 27th December 2008, 13:39
  3. signal-slot problem with QVector
    By stefan in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 14:58
  4. problem with signal/slot mechanismus
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 7th March 2008, 20:05
  5. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 23:59

Tags for this Thread

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.