title: Qt3 vs Qt5 programming syntax
body: <p>Hi I'm teaching myself Qt based on Qt 5.7.0 (MSVC 2013, 32 bit), Qt Creator 4.1.0 - community edition.  I am using an book, "Programming with Qt, 2nd Edition" by Matthias Kalle Dalheimer which focuses on QT3.  One of the exercises is to have a slider which uses the LCD number display.  There are also two buttons (add, subtract) to change the slider and LCD display.  I was not able to get the book code to work because there have been major syntax changes.</p>
  
  <p>I was able to get my code to work using the Qt designer but I want to do it without that as well.  How can I do that?  I was thinking of using events but I couldn't figure out the syntax.</p>
  
  <p>Here is the snippets from the book.</p>
  
  <pre><code>QObject::connect(decrement, SIGNAL(clicked()), myslider, SLOT(subtractStep()));
  QObject::connect(increment, SIGNAL(clicked()), myslider, SLOT(addStep()));
  </code></pre>
  
  <p>These are the error messages from the console for my code below in main.cpp:
  "QObject::connect: No such slot QSlider::SingleStep()in ..\ProgrammingQt\main.cpp:31
  QObject::connect: No such signal QSlider::triggerAction(SliderSingleStepAdd) in ..\ProgrammingQt\main.cpp:32"</p>
  
  <p>Here is my code without the ui. - main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;qapplication.h&gt;
  #include &lt;qwidget.h&gt;
  #include &lt;qslider.h&gt;
  #include &lt;qlcdnumber.h&gt;
  #include &lt;qpushbutton.h&gt;
  #include &lt;qstring.h&gt;
  
  using namespace std;
  
  int main(int argc, char* argv[])
  {
      QApplication app(argc, argv);
  
      QWidget *widget = new QWidget();
      widget-&gt;setGeometry(400, 300, 170, 150);
  
      QSlider *slider = new QSlider(Qt::Horizontal, widget);
      slider-&gt;setGeometry(10, 10, 150,30);
  
      QLCDNumber *lcd = new QLCDNumber(2, widget);
      lcd-&gt;setGeometry(60, 50, 50, 50);
      lcd-&gt;display(1);
  
      QObject::connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
  
      QPushButton *addBtn = new QPushButton("ADD ONE", widget);
      addBtn-&gt;setGeometry(10, 110, 50, 30);
      //QObject::connect(addBtn, SIGNAL(clicked(bool)), slider, SLOT(SliderSingleStepAdd()));
      //QObject::connect(addBtn, SIGNAL(clicked(bool)), slider, SLOT(SingleStep()));
      //QObject::connect(slider, SIGNAL(triggerAction(SliderSingleStepAdd)), lcd, SLOT(display(int)));
  
      QPushButton *minusBtn = new QPushButton("MINUS ONE", widget);
      minusBtn-&gt;setGeometry(100, 110, 60, 30);
     //  QObject::connect(minusBtn, SIGNAL(clicked(bool)), slider, SLOT    (SliderSingleStepSub()));
  
      QObject::connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
  
      widget-&gt;setWindowTitle("LCD Number");
      widget-&gt;show();
      return app.exec();
  }
  </code></pre>
  
  <p>Here is the code using the Qt Designer:  mainwindow.cpp</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::on_slider_valueChanged(int value)
  {
      ui-&gt;lcd-&gt;display(value);
  }
  
  void MainWindow::on_addBtn_clicked()
  {
      int incVal = ui-&gt;slider-&gt;value();
      incVal++;
      ui-&gt;slider-&gt;setValue(incVal);
      ui-&gt;lcd-&gt;display(incVal);
  }
  
  void MainWindow::on_minusBtn_clicked()
  {
      int decVal = ui-&gt;slider-&gt;value();
      decVal--;
      ui-&gt;slider-&gt;setValue(decVal);
      ui-&gt;lcd-&gt;display(decVal);
  }
  </code></pre>
  
  <p>mainwindow.h</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QSlider&gt;
  #include &lt;QLCDNumber&gt;
  
  namespace Ui {
      class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
      public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();
  
     private slots:
  
     void on_slider_valueChanged(int value);
  
     void on_addBtn_clicked();
     void on_minusBtn_clicked();
  
   private:
       Ui::MainWindow *ui;
  };
  
  #endif // MAINWINDOW_H
  </code></pre>