QSignalMapper not working.



  • Hi, i use QSignalMapper like this:
    @
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    public slots:
    void cclick(int);

    private:
    Ui::MainWindow *ui;
    QSignalMapper *signalmaper;
    };@
    in constructor:
    @
    signalmaper = new QSignalMapper(this);
    connect(signalmaper, SIGNAL(mapped(int)),this,SLOT(cclick(int)));
    ui->setupUi(this);
    signalmaper->setMapping(ui->pushButton,10);
    @

    @void MainWindow::cclick(int x)
    {

    ui->pushButton->setText("dfdff");
    

    }
    @
    but when i click on button nothing happen. any idea?


  • Lifetime Qt Champion

    Hi,

    Did you check that the slot was called ? With i.e the debugger or simply a

    @qDebug() << Q_FUNC_INFO;@

    in cclick ?

    What's the original text of pushButton ?



  • the slot not called. this is application output:
    @

    Debugging starts
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\platforms\qminimald.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\platforms\qwindowsd.dll"
    MainWindow::MainWindow(QWidget*)
    @



  • You are missing a connect statement:
    @
    connect(ui->pushButton, SIGNAL(clicked()),signalmaper,SLOT(map()));
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.