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

Bit shifts

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 3.5k 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.
  • M Offline
    M Offline
    Mike_newbye
    wrote on last edited by
    #1

    Hi,

    How can I do a bit shift in Qt? The analogue in c++ is presented bellow as a part of code:

    @while(file >> i)
    {
    elements++;
    }@

    Thanks in advance.

    Kind regards,
    Mikael

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Qt libs are usually used with C++. So you can do this as you do in C++.
      Or do you mean something specific?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mike_newbye
        wrote on last edited by
        #3

        The special staff is that in Qt file is @QFile@ and i is @int@

        Kind regards,
        Mikael

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You are not very clear. Are you trying to get data from a file or do bit shifting ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mike_newbye
            wrote on last edited by
            #5

            I am trying to calculate the elements in the file. For more clarity see the code below:

            @int kmean_algorithm::calculateElementsInFile()
            {
            int numberOfElements = 0;
            int fileIterator
            QFile file("...\iris.csv");
            if(!file.open(QIODevice::ReadOnly))
            {
            QMessageBox::warning(0, "Error", file.errorString());
            }
            if(file.isOpen())
            {
            while(file >> fileIterator)
            {
            numberOfElements ++;
            }
            }
            file.close();
            }@

            The code provided is wrong and I realize it, as >> is from fstream (if I loaded the file with standard c++ as follows ifstream file(filename); there would be no problem), as I load the file using QFile it means that file >> fileIterator is impossible w.r.t the following error about types inequality:

            bq. error: no match for 'operator>>' (operand types are 'QFile' and 'int')

            Q: How can I make >> in my case to work? Any suggestion? Alternatives?

            Kind regards,
            Mikael

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Since it's a csv, you have a file text you could use "QTextStream":http://qt-project.org/doc/qt-4.8/qtextstream.html.

              But, if I have understood you correctly you want to count all the elements contained in your csv. You could read your file line by line in a QString, and use split with the delimiter to get the actual count of the elements per line.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Buckets
                wrote on last edited by
                #7

                create a subclass of QFile with the bit shift operators.

                An easier way to get the count of either lines, or entries per line would do what SGaist suggested where you read the file in line by line into multiple buffers or the whole file into one giant buffer. Then use QString's split function with either the , or \n as your delimiter. The split function returns a QStringList which contains a count.

                ba ba ba
                ba na na na

                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