Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Trying to pass QString using connect



  • 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')



  • 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



  • @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.



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



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


  • Lifetime Qt Champion

    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...



  • @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.


Log in to reply