setWindowTitle as SLOT

  • I cannot explain myself why while this works

    connect(this, SIGNAL(mysignal()), this, SLOT(showMinimized()));

    this does not

    connect(this, SIGNAL(mysignal()), this, SLOT(setWindowTitle("blablahblah")));

    Nevertheless if I do it this way it works

    connect(this, SIGNAL(mysignal()), this, SLOT(title()));
    void MyClass::title() {

    Aren't both showMinimized and setWindowTitle SLOTS of QWidget? what makes the difference?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Because you don’t pass values as parameters of the connect methods. The form you are using expect parameter types. You should also get a warning at run time.

    You should take a look at Signals and Slots chapter of Qt’s documentation for more information on the subject.

  • If you can, use Qt5 Connect Syntax

    These 2 both work and are checked at compile time
    connect(this, &Myclass::mysignal, this, &Myclass::showMinimized);
    connect(this, &Myclass::mysignal, this, std::bind(&Myclass::setWindowTitle,this,QStringLiteral("blablahblah")));

Log in to reply