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. Code doesnt work
Qt 6.11 is out! See what's new in the release blog

Code doesnt work

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.9k 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.
  • R Offline
    R Offline
    Ruzik
    wrote on last edited by
    #1

    Hellow, plaease, tell me why my code doesnt work?
    @bool isClass = false;
    for(int a=0;a<=needNext.count();a++)
    {
    if (QString(needNext[a])!=QString(" "))
    if (QString(needNext[a])==QString("}"))
    {
    qDebug() <<"1"+ QString(needNext[a]);
    isClass=true;
    a=needNext.count();
    }
    else
    {
    a=needNext.count();
    qDebug() <<"2"+ QString(needNext[a]);
    }
    }@
    It is must find last symbol in text unequal " "(space) and if last symbol equal "{" should happen assignment
    It is always display "2 (without second qoute)
    As the text is supplied text
    @QPushButton{
    background-color: #123123;
    }@
    for example

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SimonL
      wrote on last edited by
      #2

      do you have a new line after your " ", It may be better to use regex to find your last space
      [Edit]
      A good way to debug this may be to print which character you are seeing last you may want to print this as a int value

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ruzik
        wrote on last edited by
        #3

        I dont have new line after " "

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruzik
          wrote on last edited by
          #4

          If the text = "}" code worke right, but if text = "a}" code doesnt work wright

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonL
            wrote on last edited by
            #5

            What Type is needNext?
            I suspect that you would iterate over that loop 1 to many times it should probably be a< needNext.count(); as count() probably returns the size and you probably require the size -1

            1 Reply Last reply
            0
            • S Offline
              S Offline
              soroush
              wrote on last edited by
              #6

              There is an ambiguous 'else' here. put contents of every if in {} always. also you don't need to convert QChar s to QString . they are themselves comparable.
              I assume needNext is a QString (is not?)
              try tis code:

              @ for(int a=0; a<=needNext.count(); a++)
              {
              if (needNext[a]!=QChar(' '))
              {
              if (needNext[a]==QChar('}'))
              {
              qDebug() <<"1"+ needNext[a];
              isClass=true;
              // a=needNext.count();
              // probably you mean:
              break;
              }
              else
              {
              //a=needNext.count();
              break;
              qDebug() <<"2"+ needNext[a];
              }
              }
              }@
              If you want to iterate over all characters of a QString, you may want to use a bit more elegant way using iterators:
              @
              QString::ConstIterator i = needNext.begin();
              while(i != needNext.end())
              {
              if ( *i !=QChar(' '))
              {
              if ( *i ==QChar('}'))
              {
              // ...
              i++;
              }
              @

              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