bad syntax on connect() statement

  • Hi all - my notes are at home and I've started a new job (where I'm trying to make a case for adopting Qt). I'm trying to put together a very small example, but getting an error.

    Here's the code:

    #include "widget.h"
    #include "serial.h"
    #include <QApplication>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        Widget w;
        Serial s;
        QObject::connect(s, &Serial::newText, w, &Widget::addText);;
        return a.exec();

    And here's the error:

    C:\Users\mzimmers.CYBERDATA\Qt projects\WiFiButtonProvisioner\main.cpp:12: error: no matching function for call to 'QObject::connect(Serial&, void (Serial::*)(QString), Widget&, void (Widget::*)(QString))'
         QObject::connect(s, &Serial::newText, w, &Widget::addText);

    I'm sure I'm botching the syntax, but I can't find my error. Can someone lend a hand? Thanks.

  • Qt Champions 2018

    @mzimmers said in bad syntax on connect() statement:

    QObject::connect(s, &Serial::newText, w, &Widget::addText);

    I'm pretty sure you must specify the address of s and w:

    QObject::connect(&s, &Serial::newText, &w, &Widget::addText);

  • Hi - yeah, that was it. I'd tried that, and gotten another error that was due to my not declaring QObject as a public base class. Fixed that, and it seems to work now.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.