Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Retrieve value from a signal with the new Qt5 connect syntax
QtWS25 Last Chance

Retrieve value from a signal with the new Qt5 connect syntax

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • 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 Offline
    K Offline
    kevina67
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kevina67
        wrote on last edited by
        #3

        It works, thank you. ;)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved