×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    4

    calling a funktion with Slot

    Hallo everyone,

    ich have a little problem in my code:
    i want to connect a button with a funktion that i defined in the main.cpp

    but it does not work in this way

    kann someone help me??

    void playMe()
    {
    QSound s("C://test.wav");
    s.play();
    }

    int main(int argc, char *argv[])
    {
    QPushButton *cover1 = new QPushButton;
    QObject::connect(cover1, SIGNAL(clicked()), this, SLOT(playMe()));
    }

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: calling a funktion with Slot

    Slot should be a slot of a class derived from QObject with Q_OBJECT macro.
    More details as usually in the documentation
    http://doc.trolltech.com/4.6/signalsandslots.html

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    4

    Re: calling a funktion with Slot

    thank you

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: calling a funktion with Slot

    A little hint:

    Always capture the return code from connect() and test it with an assert:

    Code:
    bool rc = connect(...);
    Q_ASSERT(rc);
    Q_UNUSED(rc);
    (The Q_UNUSED prevents the compiler from complaining about an unused variable when compiled without debug enable.)

    This way you always can be sure that your connect actually "took".

Similar Threads

  1. Jan 2010 - Calling All Innovators
    By Nokia Ron in forum News and Announcements
    Replies: 95
    Last Post: 2011-01-27, 18:34
  2. Replies: 3
    Last Post: 2010-03-27, 13:17
  3. Using calling cards with Nokia 6600
    By steffi1 in forum General Development Questions
    Replies: 3
    Last Post: 2008-01-21, 03:49
  4. nokia6288:mediaplayer restart while calling coming
    By oodoo7 in forum General Development Questions
    Replies: 0
    Last Post: 2007-01-29, 15:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×