Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problems with connect() and some classes
Forum Updated to NodeBB v4.3 + New Features

Problems with connect() and some classes

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brunoluiz
    wrote on 30 Apr 2012, 21:19 last edited by
    #1

    Good night,

    I'm writing some code here but I'm getting this error:

    @Object::connect: No such slot gaugeView::updateValues(30) in ..\teste2\mainwindow.cpp:43
    Object::connect: No such slot gaugeView::updateValues(30) in ..\teste2\mainwindow.cpp:44@

    I tried everything I found at Google, but I can't find the error. The code of the class are:

    Main Window.cpp:
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "gaugeview.h"
    #include <QFileDialog>
    #include <QTimer>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    int ra = rand();
    while(ra > 200)
    ra = rand();

    gaugeView * gauge1 = new gaugeView(centralWidget());
    ref = gauge1;
    QString pointerFile = ":/pointer.png";
    QString backgroundFile = ":/background.png";

    gauge1->setPointer(pointerFile);
    gauge1->setBackground(backgroundFile);
    gauge1->setPosition(0,0);
    gauge1->setDimensions(272,272);
    gauge1->create();
    gauge1->update(ra);

    ra = rand();
    while(ra > 200)
    ra = rand();

    gaugeView * gauge2 = new gaugeView(centralWidget());

    gauge2->setPointer(pointerFile);
    gauge2->setBackground(backgroundFile);
    gauge2->setPosition(0,271);
    gauge2->setDimensions(272,272);
    gauge2->create();
    gauge2->update(ra);

    QTimer * timerRand = new QTimer;
    connect(timerRand,SIGNAL(timeout()),gauge1,SLOT(updateValues(30)));
    connect(timerRand,SIGNAL(timeout()),gauge2,SLOT(updateValues(30)));
    timerRand->start(2000);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    //void MainWindow::updateValues(gaugeView obj, int num)
    //{
    // obj.update(num);
    //}
    @

    MainWindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "gaugeview.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    gaugeView * ref;

    //public slots:
    // void updateValues(int);
    };

    #endif // MAINWINDOW_H
    @

    gaugeview.h
    @#ifndef GAUGEVIEW_H
    #define GAUGEVIEW_H

    #include <QWidget>
    #include <QGraphicsScene>
    //#include <QPixmap>

    class gaugeView : public QWidget
    {
    Q_OBJECT
    public:
    explicit gaugeView(QWidget *parent = 0);
    void update(int);
    void create();
    void setPointer(QString);
    void setBackground(QString);
    void setPosition(int,int);
    void setDimensions(int,int);
    bool setDigital(bool);

    private:
    QPixmap pixPointer;
    QPixmap pixBackground;
    int posx, posy;
    int actualWidth,actualHeight;
    int actualValue, pastValue;
    bool showDigital;
    QGraphicsView * gp;
    QGraphicsScene * actualScene;
    void createDigital(void);

    public slots:
    void updateValues(int);
    };

    #endif // GAUGEVIEW_H
    @

    gaugeview.cpp
    @#include "gaugeview.h"
    #include <QPainter>
    #include <QGraphicsView>
    #include <QBrush>

    gaugeView::gaugeView(QWidget *parent) :
    QWidget(parent)
    {
    gp = new QGraphicsView(parentWidget());
    gp->move(0,0);
    gp->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    gp->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    gp->lower();
    }

    void gaugeView::setPointer(QString fileLocation)
    {
    pixPointer.fill(Qt::transparent);
    pixPointer.load(fileLocation);
    }

    void gaugeView::setBackground(QString fileLocation)
    {
    pixBackground.fill(Qt::transparent);
    pixBackground.load(fileLocation);
    }

    void gaugeView::setPosition(int x = 0,int y = 0)
    {
    posx = x;
    posy = y;
    gp->move(posx,posy);
    }

    bool gaugeView::setDigital(bool checkCond)
    {
    showDigital = checkCond;
    return checkCond;
    }

    void gaugeView::createDigital()
    {

    }

    void gaugeView::setDimensions(int width,int height)
    {
    actualWidth = width;
    actualHeight = height;
    pixPointer = pixPointer.scaled(actualWidth, actualHeight);
    pixBackground = pixBackground.scaled(actualWidth, actualHeight);
    }

    void gaugeView::create()
    {
    QBrush brushBackground;
    brushBackground.setTexture(pixBackground);

    actualScene = new QGraphicsScene();
    actualScene->clear();
    actualScene->addPixmap(pixPointer);

    gp->setBackgroundBrush(brushBackground);
    gp->setScene(actualScene);
    gp->show();
    }

    void gaugeView::update(int value)
    {
    pastValue = actualValue;
    actualValue = value;

    QSize size = pixPointer.size();
    QPixmap rotatedPixmap(size);
    rotatedPixmap.fill(Qt::transparent);

    QPainter * p = new QPainter(&rotatedPixmap);
    p->setRenderHint(QPainter::SmoothPixmapTransform);
    p->translate(size.width()/2,size.height()/2);
    p->rotate(actualValue);
    p->translate(-size.width()/2,-size.height()/2);
    p->drawPixmap(0,0,pixPointer);
    p->end();
    delete p;

    actualScene->clear();
    actualScene->addPixmap(rotatedPixmap);

    gp->setScene(actualScene);
    gp->move(posx,posy);
    gp->show();
    }

    void gaugeView::updateValues(int num = 0)
    {
    this->update(num);
    }
    @

    If someone have an idea of what is happening, please, post it.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 30 Apr 2012, 21:29 last edited by
      #2

      You slot should be
      @
      updateValues(int)
      @

      instead of
      @
      updateValues(30)
      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on 30 Apr 2012, 21:32 last edited by
        #3

        However,

        following statement still wrong
        @
        connect(timerRand,SIGNAL(timeout()),gauge1,SLOT(updateValues(int)));
        @

        params provided by signal should >= params needed by your slot.

        Read the manual carefully. http://doc-snapshot.qt-project.org/4.8/signalsandslots.html

        1 Reply Last reply
        0
        • B Offline
          B Offline
          brunoluiz
          wrote on 30 Apr 2012, 21:34 last edited by
          #4

          So, in this logic, how I can update my gauges with QTimer?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on 30 Apr 2012, 21:59 last edited by
            #5

            Make your gauges member variables so they are accessible throughout your class.

            Then create a slot to do that specific task. For instance:

            @
            // slot:
            void setValuesOnTimeout() {
            gauge1->updateValues(30);
            gauge2->updateValues(30);
            }
            @

            Then connect like:
            @
            connect(timerRand,SIGNAL(timeout()),this,SLOT(setValuesOnTimeout()));
            @

            Edit:

            Alternately... (I think this might work, but I haven't tried it...)

            Make the default values on your updateValues slots = 30.

            Then just connect:
            @
            // These will use the default value of 30
            connect(timerRand,SIGNAL(timeout()),gauge1,SLOT(updateValues()));
            connect(timerRand,SIGNAL(timeout()),gauge2,SLOT(updateValues()));
            @

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              brunoluiz
              wrote on 30 Apr 2012, 22:59 last edited by
              #6

              Thank you! It worked.

              [quote author="mlong" date="1335823162"]Make your gauges member variables so they are accessible throughout your class.

              Then create a slot to do that specific task. For instance:

              @
              // slot:
              void setValuesOnTimeout() {
              gauge1->updateValues(30);
              gauge2->updateValues(30);
              }
              @

              Then connect like:
              @
              connect(timerRand,SIGNAL(timeout()),this,SLOT(setValuesOnTimeout()));
              @

              Edit:

              Alternately... (I think this might work, but I haven't tried it...)

              Make the default values on your updateValues slots = 30.

              Then just connect:
              @
              // These will use the default value of 30
              connect(timerRand,SIGNAL(timeout()),gauge1,SLOT(updateValues()));
              connect(timerRand,SIGNAL(timeout()),gauge2,SLOT(updateValues()));
              @[/quote]

              1 Reply Last reply
              0

              3/6

              30 Apr 2012, 21:32

              • Login

              • Login or register to search.
              3 out of 6
              • First post
                3/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved