Important: Please read the Qt Code of Conduct -

Retrieve value from a signal with the new Qt5 connect syntax

  • Hi everybody,

    I'm writing a simple code editor using Qt5 and its new signals & slots syntax. However I got stucked with a trivial problem.

    Considering the following class:

    class CodeEditorTabWidget : public QTabWidget

    explicit CodeEditor(QWidget* parent = nullptr);
    void currentChanged(const QString& fileName);
    // Some stuff


    The currentChanged signal is emited when the file bein edited has changed. This widget is embedded in a subclass of QMainWindow called MainWindow.

    In this class I'd like to do something like:

    QObject::connect(_codeEditorTabWidget, &CodeEditorTabWidget::currentChanged, [this] () {
    setWindowTitle("My editor - " + here the QString emited by currentChanged signal);

    So my window will have as title: "My editor - /home/kevina/myClass.hpp". And it will change automatically when the user open a new file or switch to another tab.

    Is there any way to do so ?

    Thanks in advance for any help ;)

  • Couldn't you use this:
    QObject::connect(_codeEditorTabWidget, &CodeEditorTabWidget::currentChanged, [=](const QString& fileName){
    setWindowTitle(QString("My editor - %1").arg(fileName);

  • It works, thank you. ;)

Log in to reply