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. [SOLVED] cannot catch a signal

[SOLVED] cannot catch a signal

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.9k Views
  • 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.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    @
    #ifndef MAINWINDOWS_H
    #define MAINWINDOWS_H

    #include <QObject>
    #include <QWidget>
    #include <QPushButton>

    class MainWindows : public QWidget
    {
    Q_OBJECT
    public:
    explicit MainWindows(QWidget *parent = 0);

    private:
    QPushButton *ingrandimento;
    QPushButton *rimpicciolimento;

    signals:

    private slots:
    void updateAll(int newIngrandimento);
    };

    #endif // MAINWINDOWS_H
    @

    @

    include "mainwindows.h"

    #include "guida.h"
    #include "programsettings.h"
    #include <QVBoxLayout>
    #include <QDebug>

    MainWindows::MainWindows(QWidget *parent) :
    QWidget(parent)
    {
    this->setWindowFlags(Qt::FramelessWindowHint);

    QVBoxLayout *left = new QVBoxLayout(this);
    ingrandimento = new QPushButton("Non vedo!!!");
    QFont font("Calibri", 26);
    font.setBold(true);
    ingrandimento->setFont(font);
    rimpicciolimento = new QPushButton("Porto gli\nocchiali,\nma ci\nvedo\nancora!!");
    QFont font1("Calibri", 24);
    font1.setBold(true);
    rimpicciolimento->setFont(font1);
    left->addWidget(ingrandimento);
    left->addWidget(rimpicciolimento);
    QObject::connect(ingrandimento, SIGNAL(clicked()), new ProgramSettings(), SLOT(addIngrandimento()));
    QObject::connect(rimpicciolimento, SIGNAL(clicked()), new ProgramSettings(), SLOT(reduceIngrandimento()));
    QObject::connect(new ProgramSettings, SIGNAL(ingrandimentoChanged(int)), this, SLOT(updateAll(int)));
    

    }

    void MainWindows::updateAll(int newIngrandimento)
    {
    qDebug("updateAll");
    ingrandimento->resize(newIngrandimento * 100 + 100, 100 * newIngrandimento + 100);
    rimpicciolimento->resize(newIngrandimento * 100 + 100, 100 * newIngrandimento + 100);
    qDebug()<<"newIngrandimento: " + newIngrandimento;
    }
    @

    signal comes from:

    @
    #ifndef PROGRAMSETTINGS_H
    #define PROGRAMSETTINGS_H

    #include <QObject>
    #include <QRect>

    class ProgramSettings : public QObject
    {
    Q_OBJECT

    public:
    ProgramSettings(QObject *parent = 0);

    static int getIngrandimento();
    void setIngrandimento(const int nvalue = 1);
    static QRect getDesktopDims();
    static QSize getDesktopDimsAsQSize();
    static int getDesktopWidth();
    static int getDesktopHeight();
    

    signals:
    void ingrandimentoChanged(int nvalue);

    public slots:
    void addIngrandimento();
    void reduceIngrandimento();
    };

    #endif // PROGRAMSETTINGS_H
    @

    @
    #include "programsettings.h"

    #include <QSettings>
    #include <QVariant>
    #include <QDesktopWidget>
    #include <messaggioantipanico.h>
    #include <QDebug>

    ProgramSettings::ProgramSettings(QObject *parent) : QObject(parent)
    {
    }

    int ProgramSettings::getIngrandimento()
    {
    QSettings ss("SeiFreud", "Tecnophobie");
    int i = ss.value("ingrandimento", QVariant::fromValue(1)).toInt();
    return i;
    }

    void ProgramSettings::setIngrandimento(const int nvalue)
    {
    if(nvalue > 0 && nvalue < 4)
    {
    QSettings s("SeiFreud", "Tecnophobie");
    s.setValue("ingrandimento", QVariant::fromValue(nvalue));

        emit ingrandimentoChanged(nvalue);
    }
    else
    {
        MessaggioAntiPanico a("Non è possibile cambiare ulteriormente l' ingrandimento!");
        a.show();
    }
    

    }

    QRect ProgramSettings::getDesktopDims()
    {
    QDesktopWidget * d = new QDesktopWidget();
    return d->screenGeometry(-1);
    }

    QSize ProgramSettings::getDesktopDimsAsQSize()
    {
    QDesktopWidget * d = new QDesktopWidget();
    return QSize(d->width(), d->height());
    }

    int ProgramSettings::getDesktopHeight()
    {
    return ProgramSettings::getDesktopDims().width();
    }

    int ProgramSettings::getDesktopWidth()
    {
    return ProgramSettings::getDesktopDims().height();
    }

    void ProgramSettings::addIngrandimento()
    {
    this->setIngrandimento(this->getIngrandimento() + 1);
    }

    void ProgramSettings::reduceIngrandimento()
    {
    this->setIngrandimento(this->getIngrandimento() - 1);
    @

    why does not my PC handle "ingrandimentoChanged" and connect it with the relative slot "updateAll"?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      Hi,

      Try to put your ProgramSettings as a variable of your Mainwindows.
      As here, it could be already destroyed if no reference is keeped by your application.

      dmcr

      dmcr

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on last edited by
        #3

        Wonderfull!!! =))

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Neutron Stein
          wrote on last edited by
          #4

          I think you have to keep a reference to the new ProgramSettings() that you use to make the connections. You should have :
          @
          #ifndef MAINWINDOWS_H
          #define MAINWINDOWS_H

          #include <QObject>
          #include <QWidget>
          #include <QPushButton>
           
          class MainWindows : public QWidget
          {
              Q_OBJECT
          public:
              explicit MainWindows(QWidget *parent = 0);
             
          private:
              QPushButton *ingrandimento;
              QPushButton *rimpicciolimento;
              ProgramSettings *programSettings;
           
          signals:
             
          private slots:
              void updateAll(int newIngrandimento);
          };
           
          #endif // MAINWINDOWS_H
          

          @
          @
          include "mainwindows.h"

          #include "guida.h"
          #include "programsettings.h"
          #include <QVBoxLayout>
          #include <QDebug>
           
          MainWindows::MainWindows(QWidget *parent) :
              QWidget(parent)
          {
              this->setWindowFlags(Qt::FramelessWindowHint);
           
              QVBoxLayout *left = new QVBoxLayout(this);
              ingrandimento = new QPushButton("Non vedo!!!");
              QFont font("Calibri", 26);
              font.setBold(true);
              ingrandimento->setFont(font);
              rimpicciolimento = new QPushButton("Porto gli\nocchiali,\nma ci\nvedo\nancora!!");
              QFont font1("Calibri", 24);
              font1.setBold(true);
              rimpicciolimento->setFont(font1);
              left->addWidget(ingrandimento);
              left->addWidget(rimpicciolimento);
              programSettings = new ProgramSettings;
              QObject::connect(ingrandimento, SIGNAL(clicked()),programSettings , SLOT(addIngrandimento()));
              QObject::connect(rimpicciolimento, SIGNAL(clicked()), programSettings, SLOT(reduceIngrandimento()));
              QObject::connect(programSettings, SIGNAL(ingrandimentoChanged(int)), this, SLOT(updateAll(int)));
          }
           
          void MainWindows::updateAll(int newIngrandimento)
          {
              qDebug("updateAll");
              ingrandimento->resize(newIngrandimento * 100 + 100, 100 * newIngrandimento + 100);
              rimpicciolimento->resize(newIngrandimento * 100 + 100, 100 * newIngrandimento + 100);
              qDebug()<<"newIngrandimento: " + newIngrandimento;
          }
          

          @

          Never Seen !

          1 Reply Last reply
          0

          • Login

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