A
A
Alexey Mairin2017-11-18 00:33:08
Qt
Alexey Mairin, 2017-11-18 00:33:08

Signals and slots QT, why not work?

Hello!
There was a problem and somehow I don’t see a solution (
There are 2 classes, in 1 class I get the name from the edit
And I need to get this variable in the 2nd class, normal inheritance does not work, because classes that are inherited from QObject - are not inherited.
I tried to do it through signals and slots, but it doesn’t work (
It just doesn’t happen. Here is some code:
1 class, where I get the name

class MainWindow : public QMainWindow,public WorkWithArrayName
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
     void   fireSignl();
private slots:
    void on_pushButton_clicked();
    void on_actionCreateNewWindow_triggered();
    void on_pushButton_2_clicked();
private:
    Ui::MainWindow *ui;
    QSqlDatabase db;
protected:
    QString Name,Password,*qwe,*password_arr,userN;
signals:
    void foo(QString name);
};

foo method
void MainWindow::fireSignl()
{
    emit foo(userN);
}

Grade 2
class AfterRegistration : public QMainWindow, public WorkWithArrayName
{
    Q_OBJECT

public:
    explicit AfterRegistration(QWidget *parent = 0);
    ~AfterRegistration();
    void BrightContrastEffect();
private slots:
    void on_pushButton_2_clicked();
    void on_pushButton_clicked();
    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();
    void on_pushButton_8_clicked();
public slots:
    void bar(QString name);
private:
      Mat  MatImage;
      IplImage *dst=0;
      Mat dst1;
      int i,j,k=0;
       char* nameOfFile;
       char *named,*pathc,*allPA;
       QString nam;

    Ui::AfterRegistration *ui;
};

bar method
void AfterRegistration::bar(QString name)
{
    nam=name;
}

Here is the link itself, which I call in the cpp file of the second class
MainWindow mainwin;
        AfterRegistration reg;
        QObject::connect(&mainwin,SIGNAL(foo(QString)),&reg,SLOT(bar(QString)));
        mainwin.fireSignl();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2017-11-18
@m_avrina

Could you put the whole project on github or attach an archive here?
1) Why does AfterRegistration inherit from QMainWindow? There just has to be a QWidget or even a QDialog.
2) Try this connection mechanism:

QObject::connect(&mainwin, &MainWindow::foo, &reg, &AfterRegistration::bar);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question