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. bad syntax on connect() statement
Forum Updated to NodeBB v4.3 + New Features

bad syntax on connect() statement

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 551 Views 1 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    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);
        w.show();
    
        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.

    1 Reply Last reply
    0
    • aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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);
      

      Qt has to stay free or it will die.

      1 Reply Last reply
      5
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        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.

        Thanks...

        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