Currently in a situation where I want to have two classes, one a layout class controlling all the GUI items that are being displayed. Then a second class that contains implementation methods, what I would like to specifically do is press a button that would add 10 to a count number, then use this count number to update a progress bar (just a basic example so i get my head round it).

So currently looking at implementing this I decided to use Qt5 version of signals and slots, below is my current attempt which seems not to be firing off the slot even though i'm not receiving a compiler or runtime error. If anyone has an idea how I should be implementing this that would be great, or a good link to a decent example would be great.

counter.h
Qt Code:
  1. #ifndef COUNTER_H
  2. #define COUNTER_H
  3.  
  4. #include <QObject>
  5.  
  6. class counter : public QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit counter(QObject *parent = 0);
  11.  
  12.  
  13. signals:
  14.  
  15. public slots:
  16. int count();
  17.  
  18. private:
  19. static int number;
  20.  
  21. };
  22.  
  23. #endif // COUNTER_H
To copy to clipboard, switch view to plain text mode 

counter.cpp
Qt Code:
  1. #include "counter.h"
  2. #include "mainwindow.h"
  3.  
  4. int counter::number;
  5.  
  6. counter::counter(QObject *parent) :
  7. QObject(parent)
  8. {
  9. number = 10;
  10. }
  11.  
  12. int counter::count()
  13. {
  14.  
  15. number += 10;
  16. //emit countworked;
  17. qDebug() << number;
  18. return number;
  19. }
To copy to clipboard, switch view to plain text mode 

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QPushButton>
  6. #include <QWidget>
  7. #include <QApplication>
  8. #include <QPushButton>
  9. #include <QVBoxLayout>
  10. #include <QLabel>
  11. #include <QState>
  12. #include <QStateMachine>
  13. #include <QDebug>
  14.  
  15. namespace Ui {
  16. class MainWindow;
  17. }
  18.  
  19. class MainWindow : public QMainWindow
  20. {
  21. Q_OBJECT
  22.  
  23. public:
  24. explicit MainWindow(QWidget *parent = 0);
  25. ~MainWindow();
  26.  
  27. private:
  28. Ui::MainWindow *ui;
  29. };
  30.  
  31. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "counter.h"
  4. #include <QDebug>
  5. #include <iostream>
  6. #include <string>
  7. #include <sstream>
  8.  
  9.  
  10. MainWindow::MainWindow(QWidget *parent) :
  11. QMainWindow(parent),
  12. ui(new Ui::MainWindow)
  13. {
  14. ui->setupUi(this);
  15. counter counting;
  16. this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
  17. //int (counter::*intfunction)();
  18. //int count(10);
  19. //intfunction = &counter::count;
  20. connect(ui->pushButton_2,&QPushButton::clicked,&counting,&counter::count);
  21. //connect(countworked,countworkedvaluechanged(),ui->progressBar,&QProgressBar::valueChanged)
  22. // int *valuechanged = *intfunction;
  23. ui->progressBar->setValue(50);
  24. }
  25.  
  26. MainWindow::~MainWindow()
  27. {
  28. delete ui;
  29. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. MainWindow w;
  8. w.show();
  9.  
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode