0

I've written this piece of the code A QWidget which has a QSlider and QLineEdit They are connected to each other with their value. there are two new SLOTs which will convert their values and will call other widget to change its value. until here, everything works perfectly.

But I have added a new SIGNAL, which must be emmited when the value reaches 80. And after that the instance of the QAPPlication must be closed. This part doesn't work. Why?

#include "windows.h"
#include <QSlider>
#include <QLineEdit>
#include <QGridLayout>
#include <QApplication>
windows::windows(QWidget *parent) :
    QWidget(parent)
{
    sld=new QSlider(Qt::Horizontal,this);
    sld->setRange(0,100);
    led= new QLineEdit(this);
    QGridLayout *grid=new QGridLayout(this);
    grid->addWidget(sld,0,0);
    grid->addWidget(led,0,1);
    connect(led,SIGNAL(textEdited(QString)),this,SLOT(setSlider(QString)));
    connect(sld,SIGNAL(valueChanged(int)),this,SLOT(setLed(int)));
    connect(sld,SIGNAL(reached()),QApplication::instance(),SLOT(quit()));
}

void windows::setSlider(QString value)
{
    int intValue=value.toInt();
    sld->setValue(intValue);
    if(intValue>80)
        emit reached();
}

void windows::setLed(int value)
{
    QString Qvalue=QString::number(value);
    led->setText(Qvalue);
    if(value>80)
        emit reached();
}
Nixmd
  • 775
  • 5
  • 11
  • 20
  • bool success = connect(sld,SIGNAL(reached()),QApplication::instance(),SLOT(quit())); and check whether success == true? – trandatnh Aug 12 '13 at 04:53

1 Answers1

0

I'm such a stupid, reached() is not declared in sld, it's a SIGNAL in windows and then it won't be connected from sld, it should be like this:

connect(this,SIGNAL(reached()),QApplication::instance(),SLOT(quit()));

Nixmd
  • 775
  • 5
  • 11
  • 20
  • Only you could have solved the problem with the partial code you posted here :P – Sanyam Goel Aug 12 '13 at 05:09
  • Please post a SSCCE for a quick solution from now onwards :) http://sscce.org/ Hope this will help – Sanyam Goel Aug 12 '13 at 05:10
  • I think provided informations are enough, because it's including a header which contains the prototype of the class and it is not neccessary, and it's a very small practical example, but anyway thanks :) @SanyamGoel – Nixmd Aug 12 '13 at 05:22