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. How to search for a specific character in a QString
Forum Updated to NodeBB v4.3 + New Features

How to search for a specific character in a QString

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 9 Posters 45.6k Views 5 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.
  • Z zapprox

    Hi @tomy. QDoubleSpinBox can be used as you mentioned . First, to hide buttons call QAbstractSpinBox::setButtonSymbols(ButtonSymbols bs) and second call QAbstractSpinBox::setReadOnly(bool r).
    Have a nice day.

    VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #21

    QDoubleSpinBox can be used as you mentioned

    You still have to hard code the precision (number of decimals) shown so it does not solve the problem

    The differences between what we expect and what is shown using the code may happen for low of high precisions

    The maximum number of digits that can be represented in text is is std::numeric_limits<double>::digits10, you can't get meaningful results if you go beyond this limit

    "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
    1
    • Z zapprox

      Hi @tomy. QDoubleSpinBox can be used as you mentioned . First, to hide buttons call QAbstractSpinBox::setButtonSymbols(ButtonSymbols bs) and second call QAbstractSpinBox::setReadOnly(bool r).
      Have a nice day.

      tomyT Offline
      tomyT Offline
      tomy
      wrote on last edited by
      #22

      @zapprox
      You pointed to a good matter —hiding the buttons of that widget. As SGaist had suggested it firstly, I would like to use it because I thought it would solve the problems of those double numbers we were involving since above posts. But when VRonin subsequently said, it seems that we don't get more benefits of it compared to the chosen code.

      Thank you all.

      1 Reply Last reply
      0
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #23

        Didn't we discuss these precision things recently, I have a distinct impression we are running a loop ...
        This thread comes to mind.

        Read and abide by the Qt Code of Conduct

        tomyT 1 Reply Last reply
        0
        • kshegunovK kshegunov

          Didn't we discuss these precision things recently, I have a distinct impression we are running a loop ...
          This thread comes to mind.

          tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by
          #24

          @kshegunov
          No.
          The earlier issue was about the way that makes us able to show our result (say, 1000000) in real number mode not scientific.
          But after that, (this thread), we should be able to show the number of the precision suitable for each number as a result.
          We don't want to e.g., show 12.25 as 12.25000000 (just because we are able to show number in real mode). For the matter of accuracy, the user of the app expects to see the result in a professional way.
          Hope this helps.

          PS: I wish we wouldn't have anything named "storing numbers in binary mode" and "scientific notation". ;)

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

            I did not read the qFuzzyCompare documentation. shame on me. the compare to 0 should be avoided, corrected the snippet above

            "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

            tomyT 1 Reply Last reply
            0
            • tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by tomy
              #26

              I use this:

                 double tester = d;
                  double junk;
                  int precision = 0;
              
                  for(;!qFuzzyCompare(0.0,std::modf(tester,&junk));++precision,tester*=10.0){}
                  QString s = QString::number(d,'f',precision);
                  return s;
              

              How might this face a problem please?
              I want to test it on the app.

              1 Reply Last reply
              0
              • VRoninV VRonin

                I did not read the qFuzzyCompare documentation. shame on me. the compare to 0 should be avoided, corrected the snippet above

                tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by
                #27

                @VRonin
                Hi VRonin,

                If you see any problem with the code written above in my prior post compared to your edited one, please point to it. If there is a flaw, I will use the edited one in the app.

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

                  from http://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare

                  Note that comparing values where either p1 or p2 is 0.0 will not work

                  so instead of qFuzzyCompare(0.0,std::modf(tester,&junk)) use qFuzzyIsNull(std::modf(tester,&junk))

                  "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
                  • tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by tomy
                    #29

                    I don't know why you have thought that the decimal part will always be zero.

                    I've used this:

                    qFuzzyCompare(1.0,1.0+std::modf(tester,&junk))
                    
                    1 Reply Last reply
                    0
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #30

                      that will work too but the loop must go on untill the decimal part is 0 so qFuzzyIsNull is appropriate.

                      "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

                      • Login

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