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. Qt connect new syntax error
Forum Updated to NodeBB v4.3 + New Features

Qt connect new syntax error

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 5.5k Views 3 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.
  • VolebabV Offline
    VolebabV Offline
    Volebab
    wrote on last edited by
    #1

    I tried to use connect with a signal that has arguments, like this:

    connect(response, &QNetworkReply::error, this, &Webservice::error);

    But I'm getting an error:

    error: C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const' : cannot convert argument 2 from 'overloaded-function' to 'const char *'
    Context does not allow for disambiguation of overloaded function

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

      Hi
      If error is overloaded then its why,
      ( overloaded = more than one error function exists with different parameters)
      You need extra (ugly) syntax to force compiler to use the correct one
      https://forum.qt.io/topic/20998/qt5-new-signals-slots-syntax-does-not-work-solved/8

      in such cases i just use the old SLOT & SIGNAL macros as the typecast needed
      is very ugly and confusing to read later.

      VolebabV 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        If error is overloaded then its why,
        ( overloaded = more than one error function exists with different parameters)
        You need extra (ugly) syntax to force compiler to use the correct one
        https://forum.qt.io/topic/20998/qt5-new-signals-slots-syntax-does-not-work-solved/8

        in such cases i just use the old SLOT & SIGNAL macros as the typecast needed
        is very ugly and confusing to read later.

        VolebabV Offline
        VolebabV Offline
        Volebab
        wrote on last edited by
        #3

        @mrjj I prefer to use the old syntax, this one is really ugly. lol, but thank you.

        mrjjM 1 Reply Last reply
        1
        • VolebabV Volebab

          @mrjj I prefer to use the old syntax, this one is really ugly. lol, but thank you.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Volebab
          Yeah, when overloaded signals, new syntax is ugly.
          else it looks nice and is type safe
          You can also connect to a function. :)

          VolebabV 1 Reply Last reply
          0
          • mrjjM mrjj

            @Volebab
            Yeah, when overloaded signals, new syntax is ugly.
            else it looks nice and is type safe
            You can also connect to a function. :)

            VolebabV Offline
            VolebabV Offline
            Volebab
            wrote on last edited by
            #5

            @mrjj You are right, it works nicely with functions without arguments

            mrjjM 1 Reply Last reply
            1
            • VolebabV Volebab

              @mrjj You are right, it works nicely with functions without arguments

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Volebab
              also with arguments as long as its the only one with that name :)

              1 Reply Last reply
              1
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #7

                Hi, I also faced this dilemma; whether to use the old syntax (which is easier) or the new (which gives you better/more error messages when compiling). I wrote 2 macros:

                #define COMPOSEPMF(QOBJPTR,FUNC) \
                &std::decay<decltype(*QOBJPTR)>::type::FUNC
                
                #define CONNECT(SENDER,FUNC1,RECEIVER,FUNC2) \
                connect(SENDER,COMPOSEPMF(SENDER,FUNC1),RECEIVER,COMPOSEPMF(RECEIVER,FUNC2))
                

                Example on how to use them:

                CONNECT(ui->pushButton,clicked,this,buttonClicked);
                

                So you use them like the old macros but they give you the new syntax (i.e. having the cake and eating it too :-)

                Ok, what about using overloading functions? I wrote 3 more macros:

                #define COMPOSECASTPMF(QOBJPTR,ARGS,FUNC) \
                static_cast<void (std::decay<decltype(*QOBJPTR)>::type::*)(ARGS)> \
                (COMPOSEPMF(QOBJPTR,FUNC))
                
                #define CONNECTSCAST(SENDER,ARGS,FUNC1,RECEIVER,FUNC2) \
                connect(SENDER,COMPOSECASTPMF(SENDER,ARGS,FUNC1),RECEIVER, \
                COMPOSEPMF(RECEIVER,FUNC2))
                
                #define CONNECTRCAST(SENDER,FUNC1,RECEIVER,ARGS,FUNC2) \
                connect(SENDER,COMPOSEPMF(SENDER,FUNC1),RECEIVER, \
                COMPOSECASTPMF(RECEIVER,ARGS,FUNC2))
                

                Use them for overload functions like this:

                ui->comboBox->addItems({"Now","is","the","time"});
                CONNECTSCAST(ui->comboBox,const QString &,currentIndexChanged,this,indexChanged);
                
                auto sm = new QSignalMapper(ui->pushButton);
                CONNECTRCAST(ui->pushButton,clicked,sm,void,map);
                

                Ok still complicated, but maybe not as ugly as the new syntax, when dealing with overloaded functions. Also note: you need a C++11 (or later) compiler.

                VolebabV ? 2 Replies Last reply
                3
                • hskoglundH hskoglund

                  Hi, I also faced this dilemma; whether to use the old syntax (which is easier) or the new (which gives you better/more error messages when compiling). I wrote 2 macros:

                  #define COMPOSEPMF(QOBJPTR,FUNC) \
                  &std::decay<decltype(*QOBJPTR)>::type::FUNC
                  
                  #define CONNECT(SENDER,FUNC1,RECEIVER,FUNC2) \
                  connect(SENDER,COMPOSEPMF(SENDER,FUNC1),RECEIVER,COMPOSEPMF(RECEIVER,FUNC2))
                  

                  Example on how to use them:

                  CONNECT(ui->pushButton,clicked,this,buttonClicked);
                  

                  So you use them like the old macros but they give you the new syntax (i.e. having the cake and eating it too :-)

                  Ok, what about using overloading functions? I wrote 3 more macros:

                  #define COMPOSECASTPMF(QOBJPTR,ARGS,FUNC) \
                  static_cast<void (std::decay<decltype(*QOBJPTR)>::type::*)(ARGS)> \
                  (COMPOSEPMF(QOBJPTR,FUNC))
                  
                  #define CONNECTSCAST(SENDER,ARGS,FUNC1,RECEIVER,FUNC2) \
                  connect(SENDER,COMPOSECASTPMF(SENDER,ARGS,FUNC1),RECEIVER, \
                  COMPOSEPMF(RECEIVER,FUNC2))
                  
                  #define CONNECTRCAST(SENDER,FUNC1,RECEIVER,ARGS,FUNC2) \
                  connect(SENDER,COMPOSEPMF(SENDER,FUNC1),RECEIVER, \
                  COMPOSECASTPMF(RECEIVER,ARGS,FUNC2))
                  

                  Use them for overload functions like this:

                  ui->comboBox->addItems({"Now","is","the","time"});
                  CONNECTSCAST(ui->comboBox,const QString &,currentIndexChanged,this,indexChanged);
                  
                  auto sm = new QSignalMapper(ui->pushButton);
                  CONNECTRCAST(ui->pushButton,clicked,sm,void,map);
                  

                  Ok still complicated, but maybe not as ugly as the new syntax, when dealing with overloaded functions. Also note: you need a C++11 (or later) compiler.

                  VolebabV Offline
                  VolebabV Offline
                  Volebab
                  wrote on last edited by
                  #8

                  @hskoglund That is amazing actually, the second I saw your code I thought about putting it in a global header file and call it the day. Perhaps I would change a few names though. What you mean with PMF?

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Much nicer to look at :)
                    Thx for sharing

                    • having the cake and eating it too :-)

                    My favorite concept :)

                    1 Reply Last reply
                    0
                    • hskoglundH hskoglund

                      Hi, I also faced this dilemma; whether to use the old syntax (which is easier) or the new (which gives you better/more error messages when compiling). I wrote 2 macros:

                      #define COMPOSEPMF(QOBJPTR,FUNC) \
                      &std::decay<decltype(*QOBJPTR)>::type::FUNC
                      
                      #define CONNECT(SENDER,FUNC1,RECEIVER,FUNC2) \
                      connect(SENDER,COMPOSEPMF(SENDER,FUNC1),RECEIVER,COMPOSEPMF(RECEIVER,FUNC2))
                      

                      Example on how to use them:

                      CONNECT(ui->pushButton,clicked,this,buttonClicked);
                      

                      So you use them like the old macros but they give you the new syntax (i.e. having the cake and eating it too :-)

                      Ok, what about using overloading functions? I wrote 3 more macros:

                      #define COMPOSECASTPMF(QOBJPTR,ARGS,FUNC) \
                      static_cast<void (std::decay<decltype(*QOBJPTR)>::type::*)(ARGS)> \
                      (COMPOSEPMF(QOBJPTR,FUNC))
                      
                      #define CONNECTSCAST(SENDER,ARGS,FUNC1,RECEIVER,FUNC2) \
                      connect(SENDER,COMPOSECASTPMF(SENDER,ARGS,FUNC1),RECEIVER, \
                      COMPOSEPMF(RECEIVER,FUNC2))
                      
                      #define CONNECTRCAST(SENDER,FUNC1,RECEIVER,ARGS,FUNC2) \
                      connect(SENDER,COMPOSEPMF(SENDER,FUNC1),RECEIVER, \
                      COMPOSECASTPMF(RECEIVER,ARGS,FUNC2))
                      

                      Use them for overload functions like this:

                      ui->comboBox->addItems({"Now","is","the","time"});
                      CONNECTSCAST(ui->comboBox,const QString &,currentIndexChanged,this,indexChanged);
                      
                      auto sm = new QSignalMapper(ui->pushButton);
                      CONNECTRCAST(ui->pushButton,clicked,sm,void,map);
                      

                      Ok still complicated, but maybe not as ugly as the new syntax, when dealing with overloaded functions. Also note: you need a C++11 (or later) compiler.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      @hskoglund Looks like a really good idea. Thank you so much for sharing! :-*

                      1 Reply Last reply
                      1

                      • Login

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