Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. : error: ambiguous overload for ‘operator=’
Forum Updated to NodeBB v4.3 + New Features

: error: ambiguous overload for ‘operator=’

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 3 Posters 3.2k 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    I like to expand the use of my application and to this goal I like to
    declare
    QStringList expressionList ;
    as class variable member

    and define it in code
    expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"};

    I am receiving this error and I do not understand why and of course have no idea how to fix it.

    If I define it this way , in body of the code , it works just fine as a "local variable".
    QStringList expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"};

    Do I have to build the list from individual QString ?

    /mnt/MDI_RAID_5/MDI_WORK_COPY_FOLDER/MDI_BT_Aug1_BASE/MDI_BT/MDI_BT/C_BLUETOOTHCTL/C_bluetoothctl/mainwindow_bluetoothctl.cpp:5721: error: ambiguous overload for ‘operator=’ (operand types are ‘QStringList’ and ‘<brace-enclosed initializer list>’)
    mainwindow_bluetoothctl.cpp: In member function ‘void MainWindow_Bluetoothctl::on_lineEdit_8_returnPressed()’:
    mainwindow_bluetoothctl.cpp:5721:115: error: ambiguous overload for ‘operator=’ (operand types are ‘QStringList’ and ‘<brace-enclosed initializer list>’)
    5721 | expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"};
    | ^

    J.HilkJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      I like to expand the use of my application and to this goal I like to
      declare
      QStringList expressionList ;
      as class variable member

      and define it in code
      expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"};

      I am receiving this error and I do not understand why and of course have no idea how to fix it.

      If I define it this way , in body of the code , it works just fine as a "local variable".
      QStringList expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"};

      Do I have to build the list from individual QString ?

      /mnt/MDI_RAID_5/MDI_WORK_COPY_FOLDER/MDI_BT_Aug1_BASE/MDI_BT/MDI_BT/C_BLUETOOTHCTL/C_bluetoothctl/mainwindow_bluetoothctl.cpp:5721: error: ambiguous overload for ‘operator=’ (operand types are ‘QStringList’ and ‘<brace-enclosed initializer list>’)
      mainwindow_bluetoothctl.cpp: In member function ‘void MainWindow_Bluetoothctl::on_lineEdit_8_returnPressed()’:
      mainwindow_bluetoothctl.cpp:5721:115: error: ambiguous overload for ‘operator=’ (operand types are ‘QStringList’ and ‘<brace-enclosed initializer list>’)
      5721 | expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"};
      | ^

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @AnneRanch hard to tell without more context, but I think this

      expressionList = {"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"} is a probably a pure assignment, and not a construction operation and the compiler has a hard time deducting the type of the {}

      The easiest fix is probably being explicit:

      expressionList = QStringList{"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"}


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by Axel Spoerl
        #3

        @AnneRanch said in : error: ambiguous overload for ‘operator=’:

        rror: ambiguous overload for ‘operator=’ (operand types are ‘QStringList’ and ‘<brace-enclosed initializer list>’)

        You have run into a mean compiler feature.
        In short: changing your assignment to
        expressionList = QStringList({"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"});
        will solve your problem.

        The ambiguity is caused because the compiler could treat the curly-braces (i.e. a list of const char *) either as an initializer list or as iterators. A direct assignment is more permissive, that's why it works as local variable or with an assignment in the header. With the code above, a const QStringList object is directly assigned on the right side of the operator= and copied to the left side. That eliminates the ambiguity at the (relatively small) cost of creating another object.

        I hazard the guess that everyone in this forum has stumbled over this issue more than once. And if there are any who haven't: It's because I took their turns ;-)

        Software Engineer
        The Qt Company, Oslo

        A 1 Reply Last reply
        2
        • Axel SpoerlA Axel Spoerl

          @AnneRanch said in : error: ambiguous overload for ‘operator=’:

          rror: ambiguous overload for ‘operator=’ (operand types are ‘QStringList’ and ‘<brace-enclosed initializer list>’)

          You have run into a mean compiler feature.
          In short: changing your assignment to
          expressionList = QStringList({"([0-F]{2}[:]){5}[0-F]{2}","Agent registered","Controller","Pairable: yes"});
          will solve your problem.

          The ambiguity is caused because the compiler could treat the curly-braces (i.e. a list of const char *) either as an initializer list or as iterators. A direct assignment is more permissive, that's why it works as local variable or with an assignment in the header. With the code above, a const QStringList object is directly assigned on the right side of the operator= and copied to the left side. That eliminates the ambiguity at the (relatively small) cost of creating another object.

          I hazard the guess that everyone in this forum has stumbled over this issue more than once. And if there are any who haven't: It's because I took their turns ;-)

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

          @Axel-Spoerl Thanks, appreciate all the help. Since I am actually after an array of these and some entries are duplicated I went little crazy and ended up building the list in code. I actually changed to pointers and it is doing what I need. If there is an interest I will post the result after I clean it up.
          Thanks again

          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