Object::connect: No such signal
-
@Risver said in Object::connect: No such signal:
connect(&logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow()));
There is no such signal in your Login class:
signals:
void LoginSuccess();and btw:
{
ui->setupUi(this);
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
login logWindow;
connect(&logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow()));
}How long does your local variable
logWindow
live and how should this work? -
@Risver said in Object::connect: No such signal:
login logWindow;
connect(&logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow()));- compare the signal name and you will see
- never create a widget on the stack, it will be deleted right after when the variable goes out of scope
-
@Risver said in Object::connect: No such signal:
connect(&logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow()));
In addition to the above answers which you need to act on. Please do yourself a favour and switch over to using New Signal Slot Syntax, instead of the
SIGNAL
/SLOT()
macros. You would then get compile-time errors instead of the runtime ones you get now. -
@Christian-Ehrlicher said in Object::connect: No such signal:
@Risver said in Object::connect: No such signal:
connect(&logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow()));
There is no such signal in your Login class:
signals:
void LoginSuccess();and btw:
{
ui->setupUi(this);
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
login logWindow;
connect(&logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow()));
}How long does your local variable
logWindow
live and how should this work?Ohh, i did a mistake in the name, but now i corrected the signal name and it still not working.
The variable 'logWindow' is only for reference to login class. -
@Risver said in Object::connect: No such signal:
The variable 'logWindow' is only for reference to login class.
no, that's not how c++ works!
the way you wrote it, its a new local instance of the class, that, because its on the stack, will be destroyed as soon as the program code hits the } of the constructor
-
@J-Hilk said in Object::connect: No such signal:
@Risver said in Object::connect: No such signal:
The variable 'logWindow' is only for reference to login class.
no, that's not how c++ works!
the way you wrote it, its a new local instance of the class, that, because its on the stack, will be destroyed as soon as the program code hits the } of the constructor
How should i refer to this class, so that the variable is not deleted ?
-
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QObject> #include <QMainWindow> #include "signup.h" #include "login.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); public slots: void nextWindow(); private slots: void on_login_clicked(); void on_signup_clicked(); private: Ui::MainWindow *ui; Login *m_logWindow{nullptr}; // m_ prefix so we see its a member variable of the class };
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); setWindowFlags(Qt::MSWindowsFixedSizeDialogHint); m_logWindow = new Login(this); //I assume Login is a Widget at heart so we pass on parent so that Qt manages the memory for us //connect(m_logWindow, SIGNAL(loginSucces()), this, SLOT(nextWindow())); connect(m_logWindow,&Login::loginSucces, this, &MainWindow::nextWindow); // Better use the new syntax } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_login_clicked() { m_logWindow->show(); } void MainWindow::on_signup_clicked() { signup * signupWindow = new signup(); signupWindow->show(); } void MainWindow::nextWindow() { ui->stackedWidget->setCurrentIndex(1); }
-
@J-Hilk said in Object::connect: No such signal:
connect(m_logWindow,&Login::loginSucces, this, &MainWindow::nextWindow);
I did as you said and now i have :
no matching member function for call to 'connect' candidate function [with Func1 = void (login::*)(), Func2 = void (MainWindow::*)()] not viable: no known conversion from 'login' to 'const typename QtPrivate::FunctionPointer<void (login::*)()>::Object *' (aka 'const login *') for 1st argument; take the address of the argument with & candidate function not viable: no known conversion from 'login' to 'const QObject *' for 1st argument; take the address of the argument with & no matching function for call to 'MainWindow::connect(login&, void (login::*)(), MainWindow*, void (MainWindow::*)())' ../DiffPassV2/mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)': ../DiffPassV2/mainwindow.cpp:11:76: error: no matching function for call to 'MainWindow::connect(login&, void (login::*)(), MainWindow*, void (MainWindow::*)())' connect(m_logWindow,&login::LoginSuccess, this, &MainWindow::nextWindow); etc.
-
@Risver said in Object::connect: No such signal:
m_logWindow
This should be a pointer but it's not in your code.
-
@Christian-Ehrlicher said in Object::connect: No such signal:
@Risver said in Object::connect: No such signal:
m_logWindow
This should be a pointer but it's not in your code.
Thanks now i have no errors, but it is not switching between the stacked widgets
Sorry, that i don't reply faster but i have a 600s limit
Thanks J.Hilk -
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QObject> #include <QMainWindow> #include "signup.h" #include "login.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); public slots: void nextWindow(); private slots: void on_login_clicked(); void on_signup_clicked(); private: Ui::MainWindow *ui; login * m_logWindow{nullptr}; }; #endif // MAINWINDOW_H
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); setWindowFlags(Qt::MSWindowsFixedSizeDialogHint); m_logWindow = new login(this); connect(m_logWindow,&login::LoginSuccess, this, &MainWindow::nextWindow); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_login_clicked() { login * loginWindow = new login(); loginWindow->show(); } void MainWindow::on_signup_clicked() { signup * signupWindow = new signup(); signupWindow->show(); } void MainWindow::nextWindow() { ui->stackedWidget->setCurrentIndex(1); }
#ifndef LOGIN_H #define LOGIN_H #include <QDialog> #include <QPoint> #include <QObject> #include <QMouseEvent> #include "mainwindow.h" namespace Ui { class login; } class login : public QDialog { Q_OBJECT public: explicit login(QWidget *parent = nullptr); ~login(); private slots: void on_exit_clicked(); void on_pushButton_clicked(); private: Ui::login *ui; void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); int m_nMouseClick_X_Coordinate; int m_nMouseClick_Y_Coordinate; signals: void LoginSuccess(); }; #endif // LOGIN_H
#include "login.h" #include "ui_login.h" #include "dbmanager.h" #include <QMessageBox> login::login(QWidget *parent) : QDialog(parent), ui(new Ui::login) { ui->setupUi(this); setWindowFlags(Qt::Window | Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TransparentForMouseEvents); } login::~login() { delete ui; } void login::mousePressEvent(QMouseEvent *event) { m_nMouseClick_X_Coordinate = event->position().x(); m_nMouseClick_Y_Coordinate = event->position().y(); } void login::mouseMoveEvent(QMouseEvent *event) { move(event->globalPosition().x() - m_nMouseClick_X_Coordinate, event->globalPosition().y() - m_nMouseClick_Y_Coordinate); } void login::on_exit_clicked() { this->close(); } void login::on_pushButton_clicked() { dbManager db; QString username = ui->username->text(); QString password = ui->password->text(); db.Login(username, password); if(db.log < 1) QMessageBox::about(this, "error", "Your login or password is not correct"); if(db.log == 1) { QMessageBox::about(this, "login", "Login successful"); emit LoginSuccess(); this->close(); } }
-
see
you didn't change this functionvoid MainWindow::on_login_clicked() { login * loginWindow = new login(); loginWindow->show(); }
thats the same error as in the constructor, use the member instance
void MainWindow::on_login_clicked() { m_logWindow->show(); }