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. Trying to pass QString using connect
Forum Updated to NodeBB v4.3 + New Features

Trying to pass QString using connect

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 307 Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    I understand passing QString is different, however, I cannot figure out what is wrong with my code.
    Any factual help would be appreciated.

    QString text("TEST passing QString ");

    connect(ui->quitButton,
    SIGNAL(clicked()),
    form,
    SLOT (myFunction(text)));

    SLOT :
    void myFunction(QString const& theMsg);

    void TabWidget_Chat::myFunction(QString const& theMsg)
    {
    // qDebug(text);
    ui->label_5->setText("TEST TEXT");
    ui->label_5->setText(theMsg);
    qDebug() <<Q_FUNC_INFO;
    ui->list_2->addItem(theMsg);
    };

    Run time error :

    Chat::Chat(QWidget*) @ line 121
    QObject::connect: No such slot TabWidget_Chat::myFunction(&text) in /media/qe/RAID_CAT_MD0/QT_PROGRAMS/JULY 11 WORKCOPY 1/EXAMPLES_COPY_5.x/Examples/Qt-6.2.0/bluetooth/btchat/chat.cpp:269
    QObject::connect: (sender name: 'quitButton')
    QObject::connect: (receiver name: 'TabWidget_Chat')

    ODБOïO JonBJ 2 Replies Last reply
    0
    • A Anonymous_Banned275

      I understand passing QString is different, however, I cannot figure out what is wrong with my code.
      Any factual help would be appreciated.

      QString text("TEST passing QString ");

      connect(ui->quitButton,
      SIGNAL(clicked()),
      form,
      SLOT (myFunction(text)));

      SLOT :
      void myFunction(QString const& theMsg);

      void TabWidget_Chat::myFunction(QString const& theMsg)
      {
      // qDebug(text);
      ui->label_5->setText("TEST TEXT");
      ui->label_5->setText(theMsg);
      qDebug() <<Q_FUNC_INFO;
      ui->list_2->addItem(theMsg);
      };

      Run time error :

      Chat::Chat(QWidget*) @ line 121
      QObject::connect: No such slot TabWidget_Chat::myFunction(&text) in /media/qe/RAID_CAT_MD0/QT_PROGRAMS/JULY 11 WORKCOPY 1/EXAMPLES_COPY_5.x/Examples/Qt-6.2.0/bluetooth/btchat/chat.cpp:269
      QObject::connect: (sender name: 'quitButton')
      QObject::connect: (receiver name: 'TabWidget_Chat')

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi
      You are using the old connet syntax, modern one here https://wiki.qt.io/New_Signal_Slot_Syntax

      The signature of your signal does not match with the signature of your slot, your slot "myFunction(text)" needs to recive a QString but the clicked() signal does not provide it

      A lambda function might help

      A 1 Reply Last reply
      3
      • A Anonymous_Banned275

        I understand passing QString is different, however, I cannot figure out what is wrong with my code.
        Any factual help would be appreciated.

        QString text("TEST passing QString ");

        connect(ui->quitButton,
        SIGNAL(clicked()),
        form,
        SLOT (myFunction(text)));

        SLOT :
        void myFunction(QString const& theMsg);

        void TabWidget_Chat::myFunction(QString const& theMsg)
        {
        // qDebug(text);
        ui->label_5->setText("TEST TEXT");
        ui->label_5->setText(theMsg);
        qDebug() <<Q_FUNC_INFO;
        ui->list_2->addItem(theMsg);
        };

        Run time error :

        Chat::Chat(QWidget*) @ line 121
        QObject::connect: No such slot TabWidget_Chat::myFunction(&text) in /media/qe/RAID_CAT_MD0/QT_PROGRAMS/JULY 11 WORKCOPY 1/EXAMPLES_COPY_5.x/Examples/Qt-6.2.0/bluetooth/btchat/chat.cpp:269
        QObject::connect: (sender name: 'quitButton')
        QObject::connect: (receiver name: 'TabWidget_Chat')

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @AnneRanch said in Trying to pass QString using connect:

        Any factual help would be appreciated.

        Fact: If you were prepared to use new style signals/slots you would not get runtime error.

        A 1 Reply Last reply
        2
        • ODБOïO ODБOï

          hi
          You are using the old connet syntax, modern one here https://wiki.qt.io/New_Signal_Slot_Syntax

          The signature of your signal does not match with the signature of your slot, your slot "myFunction(text)" needs to recive a QString but the clicked() signal does not provide it

          A lambda function might help

          A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by
          #4

          @ODБOï How stupid of me. No source of text... Thanks.

          1 Reply Last reply
          0
          • JonBJ JonB

            @AnneRanch said in Trying to pass QString using connect:

            Any factual help would be appreciated.

            Fact: If you were prepared to use new style signals/slots you would not get runtime error.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @JonB PLEASE no more , you do not get the problems and just repeat your memorized phrases. It does not help.
            Save your time.

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Maybe it could be even easier - do what we suggest and all will work and save our time instead asking the same question over and over again...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • A Anonymous_Banned275

                @JonB PLEASE no more , you do not get the problems and just repeat your memorized phrases. It does not help.
                Save your time.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @AnneRanch said in Trying to pass QString using connect:

                @JonB PLEASE no more , you do not get the problems and just repeat your memorized phrases. It does not help.
                Save your time.

                I absolutely, 100% get the problem. It seems to be you who do not! It's what you need to do, as not only I but others have told you, but you prefer to keep asking the same question over and over in this forum. Why you can't take the advice I don't know. But each time you post with the same problem I'll give you & others the same solution.

                I don't know why you're hostile to me, I try to be as polite as possible to you.

                Whether you like it or not, both @ODБOï and I are giving you the same reason and advice above. You would need a lambda here to pass your "message" parameter to the slot, and you can only do that with new-style signal/slot syntax, not old style.

                1 Reply Last reply
                2

                • Login

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