T
T
TAnonim2016-08-07 17:30:24
Qt
TAnonim, 2016-08-07 17:30:24

Why doesn't the title of the Qt window change?

In general, I want to make the window title change by pressing ctrl + space.
Here is the code:

int main(int argc, char **argv){
    QApplication app(argc, argv);
    QWidget wgt;
    QAction *act = new QAction("Действие!",0);
    act->setShortcut(QKeySequence("CTRL+ "));
    wgt.addAction(act);
    wgt.show();
    wgt.resize(300,300);
    QObject::connect(act, SIGNAL(triggered()), &wgt, SLOT(setWindowTitle("sasdfasdf")));
    return app.exec();
}

But the title of the window stubbornly does not change. At the same time, if you put any other slot instead of setWindowTitle(), for example showMinimized - the application is successfully minimized. And if you call the wgt.setWindowTitle() method in the body of the main function, then the title changes. Why doesn't the name change work with ctrl + space?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2016-08-07
@TAnonim

You cannot pass parameters to connect. Try the new signal and slot syntax + closure:

connect(act, &QAction::triggered, [=]() { 
    wgt.setWindowTitle("sasdfasdf"); 
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question