Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Retrieve value from a signal with the new Qt5 connect syntax

    General and Desktop
    2
    3
    1190
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kevina67 last edited by

      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
      {
      Q_OBJECT

      public:
      
      explicit CodeEditor(QWidget* parent = nullptr);
      
      signals:
      
      void currentChanged(const QString& fileName);
      
      private:
      
      // 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 ;)

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

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

        1 Reply Last reply Reply Quote 0
        • K
          kevina67 last edited by

          It works, thank you. ;)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post