Results 1 to 11 of 11

Thread: Signals and Slots across different classes (Qt5 Version)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Sep 2014
    Posts
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signals and Slots across different classes (Qt5 Version)

    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
    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. signals:
    13. void Increment_Count(int newcount);
    14.  
    15. public slots:
    16. void count();
    17.  
    18.  
    19. private:
    20. static int number;
    21.  
    22. };
    23.  
    24. #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. void counter::count()
    13. {
    14.  
    15. number += 10;
    16. emit Increment_Count(number);
    17. qDebug() << number;
    18. // return number;
    19. }
    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 = new counter(this);
    16. this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
    17.  
    18. connect(ui->pushButton_2,&QPushButton::clicked,counting,&counter::count);
    19. connect(counting, &counter::Increment_Count(10), ui->progressBar, &QProgressBar::setValue());
    20. //connect(counting, counting->Increment_Count(), ui->progressBar, &QProgressBar::setValue());
    21. }
    22.  
    23. MainWindow::~MainWindow()
    24. {
    25. delete ui;
    26. }
    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.
    Last edited by Ion; 16th September 2014 at 10:24.

Similar Threads

  1. Replies: 2
    Last Post: 18th April 2013, 12:15
  2. Replies: 2
    Last Post: 29th June 2012, 09:32
  3. Accessing slots of other classes
    By papillon in forum Qt Programming
    Replies: 1
    Last Post: 14th January 2011, 06:24
  4. Signals/slots between classes
    By been_1990 in forum Qt Programming
    Replies: 19
    Last Post: 27th November 2009, 13:04
  5. Signals and Slots between 2 classes
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2006, 00:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.