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. Comparison of QChars
Qt 6.11 is out! See what's new in the release blog

Comparison of QChars

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 3.6k 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.
  • L Offline
    L Offline
    LogiSch17
    wrote on last edited by
    #1

    Hi guys,
    sry for this nooby question, but i am trying to compare a QChar out of a QString with a simple char and i dont get it.

    I have simply a line of numbers and want to seperate it where a ":" is.
    For example 315:15 -> x=315 , y=15

    here is my code

    QString part1="";
    QString part2="";
    bool before;
    for(int y=0; y < line.size(); y++){
            if( before && line.at(y)!=":")){
                            part1 += line.at(y);
             }else if(line.at(y)==":"){
                            before = false;
             }else if(!before && line.at(y)=""){
                            part2 += line.at(y);
            }
    }
    

    In this case i get the errror:

     error: no match for 'operator==' (operand types are 'const QChar' and 'const char [2]')
    

    so i tried to cast the char, but it is still a QChar[2] . And i do not understand how a simple char can be a QChar array of 2.
    So i tried:

    QChar seperator = (QChar)(":");
    

    Same problem. So what i am doing wrong here?

    1 Reply Last reply
    0
    • J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      I think, the error in your code is here:

      }else if(!before && line.at(y)=""){
                              part2 += line.at(y);
              }
      

      thats a typo, = needs to be a == for a valid if statement.

      Anyway have you thought about useing

      split(':')
      

      could make things simpler for you.


      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
      0
      • L Offline
        L Offline
        LogiSch17
        wrote on last edited by
        #3

        oh ,
        in the code i had i correctly.
        But i always tells me that ":" is an const char [2]

        But split() is exactly what i was looking for.
        Thanks a lot for that.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Side Note: the problem your compiler is warning you about is that ":" is actually a string so 2 chars, a : and the null termination(\0). use single quotes for single chars, ':'

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            If I may - split() is horrible. It creates a list of copies - really bad for performance. Please use splitRef() when parsing data. It creates a vector of StringRefs, a much better solution if you don't need to copy the data (and you don't need to here) and a much more cache friendy structure.

            1 Reply Last reply
            3

            • Login

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