Please help me with easy problems. How to connect(//)



  • Please help to russian newcomer)
    My english is not enough to understand documentation very well.
    I have 2 problems.

    This coonect doesn't work:
    connect( &error, SIGNAL( isVisible(bool) ), this, SLOT( setDisabled(bool) ));
    error is static member of class(this)
    I need to do this rulls:
    error.hide()<=>this.Enabled()
    error.show()<=>this.Disabled()

    How to connect Enter key pressing(in this) with changing focus to next object, like Tab key does?



  • The common connect syntax is :

    @QObject::connect(senderObject, SIGNAL(mySignal()), receiverObject, SLOT(mySlot()));@

    Where :

    • senderObject is a pointer to a QObject, commonly to a QWidget, for instance QPushButton.
    • mySignal() is the signal you're listening to, for example clicked() signal for a QPushButton.
    • receiverObject is a pointer to a QObject that has the slot you'd like to call.
    • mySlot() is the slot you want to call.

    Example :

    @MyMainWindow::MyMainWindow()
    {
    QPushButton* myButton = new QPushButton("Close");
    QObject::connect(myButton, SIGNAL(clicked()), this, SLOT(close()));
    }@

    Considering you have a class called MyMainWindow that inherits from QMainWindow. So you create a QPushButton, and when someone click on it, the window will be closed. Because the slot called close() of the QMainWindow will be call.



  • Yes, I know it.
    Sorry I did't see "Code key" here, and my post is't correct.

    This is problem connect:
    @/*Need this:
    error.hide()<=>OboiCalc.Enabled()
    error.show()<=>OboiCalc.Disabled()
    */@
    @OboiCalc::OboiCalc(QWidget *parent):QWidget(parent)
    {
    //....
    connect(&error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
    //...
    }@
    @
    class OboiCalc : public QWidget,
    {
    private:
    QDialog error;
    //...
    }
    @



  • Ok, now I see your problem :

    @
    OboiCalc::OboiCalc(QWidget* parent) : QWidget(parent)
    {
    connect(error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
    }
    @

    error should be a pointer to a QDialog.

    @
    class OboiCalc : public QWidget
    {
    private :

    QDialog* error;
    

    }
    @

    This should work fine now



  • but I use here "&", as in another connects, which work very well.
    @connect(error.pushButton, SIGNAL(clicked()), &error, SLOT(hide()));
    connect(error.pushButton_2, SIGNAL(clicked()), &error, SLOT(hide ()));@
    It is compiled, but SLOT(setDisabled) of OboiCalc doesn't work.



  • I made error as a pointer to a QDialog and added -> to all methods, but program exited with code -1073741819.



  • Which slot doesn't work?
    You should put something like qDebug()<<"in slot"; at first line of slot (don't forget include QDebug) to see if the problem is with connect or in slot code, if you won't get "in slot" in application output after you call slot the problem is with connecting. Try it and if you won't find the problem by yourself post code.
    And to your error, have you created the object? Add this line to your code if not: @ error=new QDialog(this);@ where you need to create the dialog.



  • "This is sourse":https://docviewer.yandex.ru/?url=ya-disk:///disk/Oboi.rar&name=Oboi.rar&c=5156c2610790
    click at" Скачать оригинал " on the top.
    Then if you click at first button("Счет") the window chould setDisable, but it shouldn't. This is problem.



  • please post your code here(just the part with issue), I can't speak/read Russian well and it wants me to log in to see the code, I am not going to create account^^



  • Sorry I did't know, what you must have accaunt to download)
    Look at calc.cpp.
    @//calc.h
    #ifndef CALC_H
    #define CALC_H
    #include <QDialog>
    #include "ui_OboiCalc.h"
    #include <Error.h>

    class OboiCalc : public QWidget, public Ui::OboiCalc
    {
    Q_OBJECT
    public:
    OboiCalc(QWidget *parent = 0);
    private:
    Error1 error;
    protected slots:
    void setValue();
    void clearCalc();
    };

    #endif // CALC_H
    @
    @//Error.h
    #ifndef ERROR_H
    #define ERROR_H
    #include <QDialog>
    #include "ui_Error1.h"

    class Error1 : public QDialog, public Ui::Error1
    {
    Q_OBJECT
    public:
    Error1(QWidget parent = 0);
    };
    #endif // ERROR_H
    @
    @//calc.cpp
    #include <QtGui>
    #include "Calc.h"
    #include <Error.h>
    OboiCalc::OboiCalc(QWidget parent):QWidget(parent)
    {
    setupUi(this);
    spinBox2_3->setDisabled(true);
    //
    **********************************
    connect(&error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));//This connect doesn't work =(
    //************************************
    connect(buttonOk, SIGNAL(clicked()), this, SLOT(setValue()));
    connect(buttonClear, SIGNAL(clicked()), this, SLOT(clearCalc()));
    connect(error.pushButton, SIGNAL(clicked()), &error, SLOT(hide()));
    connect(error.pushButton_2, SIGNAL(clicked()), &error, SLOT(hide ()));
    connect(error.pushButton_2, SIGNAL(clicked()), this, SLOT(clearCalc()));
    connect(checkBox, SIGNAL(clicked(bool)), spinBox2_3, SLOT(setEnabled(bool)));

    }
    void OboiCalc::clearCalc()
    {
    //something
    }
    void OboiCalc::setValue()//вывод
    {
    //something
    error.show();

    }
    @
    @//error.cpp
    #include <QtGui>
    #include <Calc.h>
    #include <Error.h>
    Error1::Error1(QWidget *parent): QDialog(parent)
    {
    setupUi(this);

    }
    @



  • actually you haven't created object error so you cant connect it.
    You should connect these 2 buttons in error.cpp in constructor, so from this:
    @
    connect(error.pushButton, SIGNAL(clicked()), &error, SLOT(hide()));
    connect(error.pushButton_2, SIGNAL(clicked()), &error, SLOT(hide ()));
    @
    make this: @
    Error1::Error1(QWidget *parent): QDialog(parent)
    {
    setupUi(this);
    connect(pushButton, SIGNAL(clicked()), this, SLOT(hide()));
    connect(pushButton_2, SIGNAL(clicked()), this, SLOT(hide ()));

    }@
    Don't forget create slots before debugging (at least empty) or you get errors.

    and to connect these 2:
    @
    connect(error.pushButton_2, SIGNAL(clicked()), this, SLOT(clearCalc()));
    connect(&error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
    @
    you have to have created object:
    @
    //in constructor or somewhere:
    connect(something,SIGNAL(someSignal()),this,SLOT(errorMessage()));
    @
    make slot that creates error message
    @
    void OboiCalc::errorMessage(){
    Error1* error = new Error1(this);
    connect(error->pushButton_2, SIGNAL(clicked()), this, SLOT(clearCalc()));
    connect(error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
    error->show();
    }
    @



  • Thank you! I understood)



  • No problem, ask more if you there is something you need to help with, otherwise mark thread [Solved] (edit post and add [Solved] to title). :)


Log in to reply
 

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