×

Discussion Board

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

    signals and slots

    Hi,
    I am developing a small application to illustrate signals and slots.
    the application has one button and label.
    If I click on button It should change the label's text.

    And my application is......


    quitApp::quitApp(QWidget *parent)
    : QWidget(parent)
    {
    //ui.setupUi(this);
    QPushButton *click = new QPushButton("click me", this);
    click->setGeometry(50, 40, 75, 30);
    label=new QLabel("one",this);
    connect(click, SIGNAL(clicked()), label, SLOT(changeText()));
    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->addWidget(click);
    layout->addWidget(label);
    }
    void quitApp::changeText()
    {
    label->setText("two");
    }



    Thanks,
    Prathibha.

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: signals and slots

    Setting custom geometry for button affects application look & feel.

  3. #3
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: signals and slots

    Quote Originally Posted by prathibha83 View Post
    Hi,
    I am developing a small application to illustrate signals and slots.
    the application has one button and label.
    If I click on button It should change the label's text.

    And my application is......


    quitApp::quitApp(QWidget *parent)
    : QWidget(parent)
    {
    //ui.setupUi(this);
    QPushButton *click = new QPushButton("click me", this);
    click->setGeometry(50, 40, 75, 30);
    label=new QLabel("one",this);
    connect(click, SIGNAL(clicked()), label, SLOT(changeText()));
    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->addWidget(click);
    layout->addWidget(label);
    }
    void quitApp::changeText()
    {
    label->setText("two");
    }



    Thanks,
    Prathibha.
    I didan't get you exactly. What is the exact problem?? Search wiki to get example that show use of signals and slots.

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: signals and slots

    It's always good practice to capture the return code from "connect" and test it with an assert. Eg:

    bool rc = connect(click, SIGNAL(....
    Q_ASSERT(rc);
    Q_UNUSED(rc);

    (The Q_UNUSED prevents the compiler from complaining about unused variables when you compile with assertion checks turned off.)

    Doing this check can help detect a lot of irritating errors in signal syntax.

Similar Threads

  1. Custom Signals
    By leighw@leigh-moana.com in forum Qt
    Replies: 2
    Last Post: 2010-06-03, 21:32
  2. CSession2 message slots
    By sssent in forum Symbian
    Replies: 3
    Last Post: 2008-11-05, 18:58
  3. URGENT: VM runs out of RSocketServ message slots
    By leapy in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2007-11-27, 01:47
  4. URGENT: Java ME VM runs out of RSocketServ message slots
    By leapy in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-11-22, 19:50

Posting Permissions

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