0

i read other questions about the same issue but wasn't able to solve mine. When i run my code, the program starts, send QObject::connect: No such slot mywindow::changerLargeur(int) and then fails. thanks you for your help

h file

#ifndef MYWINDOW_H
#define MYWINDOW_H
#include <QWidget>
#include <QSlider>
#include <QLCDNumber>

class mywindow : public QWidget
{
    Q_OBJECT
public:
    mywindow();
public slots:
    void changerlargeur(int largeur);

private:
    QSlider *glisseur;
    QLCDNumber *afficheur;    
};

#endif // MYWINDOW_H

cpp file

#include "mywindow.h"

mywindow::mywindow(): QWidget() 
{
  setFixedSize(200, 100);

  glisseur = new QSlider(Qt::Horizontal,this);
  glisseur->setRange(100,900);
  glisseur->setGeometry(10, 60, 150, 20);
  QObject::connect(glisseur, SIGNAL(valueChanged(int)), this, SLOT(changerLargeur(int)));
  QObject::connect(glisseur, SIGNAL(valueChanged(int)), afficheur, SLOT(display(int)));

  afficheur = new QLCDNumber(this);
  afficheur->setSegmentStyle(QLCDNumber::Flat);
} 

void mywindow::changerlargeur(intlargeur)
{
  setFixedSize(largeur, 100);
}

main file

#include <QApplication>
#include "mywindow.h"


int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  mywindow fenetrep;
  fenetrep.show(); 

  return app.exec(); 
}
user657267
  • 20,568
  • 5
  • 58
  • 77
domtbow
  • 3
  • 2

1 Answers1

0

Like most other things in C++, Qt's signals and slots are case sensitive. So this won't work:

void changerlargeur(int largeur);

vs.

SLOT(changerLargeur(int))

You need to decide whether you want the L to be upper or lower case and stick with it.

Another issue is this:

QObject::connect(glisseur, SIGNAL(valueChanged(int)), afficheur, SLOT(display(int)));

afficheur = new QLCDNumber(this);

You can't connect to a slot on an object that doesn't exist yet.

MrEricSir
  • 8,044
  • 4
  • 30
  • 35
  • thank you i'm a beginner in both c++ and Qt! did you noticed other errors because now the program is failling without error alert. i thank you in advance for your help – domtbow Jul 28 '14 at 00:30
  • with that in mind is that a "good pratice" to put all connect at the end of the class? – domtbow Jul 28 '14 at 00:35
  • I'm no expert on QWidget's, but I would think you would want to use a QWindow of some sort there. You might check out these examples from the Qt documentation: http://qt-project.org/doc/qt-5/examples-mainwindow.html – MrEricSir Jul 28 '14 at 00:35
  • @domtbow in our company we usually have functions for connecting signals and slots. we also `assert` the result of `QObject::connect` to ensure everything is connected – Zaiborg Jul 28 '14 at 08:22