Answer the question
In order to leave comments, you need to log in
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);
};
void MainWindow::fireSignl()
{
emit foo(userN);
}
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;
};
void AfterRegistration::bar(QString name)
{
nam=name;
}
MainWindow mainwin;
AfterRegistration reg;
QObject::connect(&mainwin,SIGNAL(foo(QString)),®,SLOT(bar(QString)));
mainwin.fireSignl();
Answer the question
In order to leave comments, you need to log in
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, ®, &AfterRegistration::bar);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question