Thanks for replying guys, d_stranz just trying out your code but a little stuck as it's complaining about not being supplied arguements to countincremented.
Yes this is what I wanted to do this is just for testing the new method of signal and slots so that I understand it correctly.
currently getting failure due to no matching function call, (incorrect amount of arguments supplied). As I supposed to give count_incremented a parameter in the connect or am I doing something else wrong (should I be using a lamda function or ?). Also "&QProgressBar::setValue() is also failing with the same thing (no matching function for call, too many arguements)
Code listed below
Counter.h
#ifndef COUNTER_H
#define COUNTER_H
#include <QObject>
{
Q_OBJECT
public:
explicit counter
(QObject *parent
= 0);
signals:
void Increment_Count(int newcount);
public slots:
void count();
private:
static int number;
};
#endif // COUNTER_H
#ifndef COUNTER_H
#define COUNTER_H
#include <QObject>
class counter : public QObject
{
Q_OBJECT
public:
explicit counter(QObject *parent = 0);
signals:
void Increment_Count(int newcount);
public slots:
void count();
private:
static int number;
};
#endif // COUNTER_H
To copy to clipboard, switch view to plain text mode
Counter.cpp
#include "counter.h"
#include "mainwindow.h"
int counter::number;
counter
::counter(QObject *parent
) :{
number = 10;
}
void counter::count()
{
number += 10;
emit Increment_Count(number);
qDebug() << number;
// return number;
}
#include "counter.h"
#include "mainwindow.h"
int counter::number;
counter::counter(QObject *parent) :
QObject(parent)
{
number = 10;
}
void counter::count()
{
number += 10;
emit Increment_Count(number);
qDebug() << number;
// return number;
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "counter.h"
#include <QDebug>
#include <iostream>
#include <string>
#include <sstream>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
counter * counting = new counter(this);
this
->setWindowTitle
(QApplication::translate("toplevel",
"CCTV"));
connect(ui->pushButton_2,&QPushButton::clicked,counting,&counter::count);
connect(counting, &counter::Increment_Count(10), ui->progressBar, &QProgressBar::setValue());
//connect(counting, counting->Increment_Count(), ui->progressBar, &QProgressBar::setValue());
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "counter.h"
#include <QDebug>
#include <iostream>
#include <string>
#include <sstream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
counter * counting = new counter(this);
this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
connect(ui->pushButton_2,&QPushButton::clicked,counting,&counter::count);
connect(counting, &counter::Increment_Count(10), ui->progressBar, &QProgressBar::setValue());
//connect(counting, counting->Increment_Count(), ui->progressBar, &QProgressBar::setValue());
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Thanks for the help so far so where am I going wrong?Just want to be able to use a signal and slot to change the progressbar via a count variable (should I be using a different method like a signal mapper ?). As I said just want two buttons to control a single instance of count, would like to be able to adjust the number for both which would be nice, but not required as this is just an example so it makes it easier for me to learn. Thanks for your help so far.
Bookmarks