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. Use of Variable or Constant
Forum Updated to NodeBB v4.3 + New Features

Use of Variable or Constant

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 1.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.
  • F Offline
    F Offline
    freesix
    wrote on 12 Aug 2014, 20:25 last edited by
    #1

    Hi guys,

    I wanted to know use of variables or constants not to directly use "mDir.AllDirs" and "mDir.count()" within qDebug as what is in the code below.

    I mean to put "mDir.AllDirs" and "mDir.count()" in different variables, then I may use them through qDebug.

    @
    QDir mDir("C:/Windows/System32");

    foreach(QFileInfo mitm, mDir.entryList())
    {
        qDebug() << mitm.absoluteFilePath();
    }
    
    qDebug () <<"\nNumber of directories :" <<mDir.AllDirs <<"items";
    
    qDebug () <<"\nNumber of files :" <<mDir.count() <<"items";
    

    @

    PS : Logic will get you from A to B, but Imagination will take you everywhere...

           Albert Einstein
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 13 Aug 2014, 05:42 last edited by
      #2

      AllDirs is "an enum value in QDir":http://qt-project.org/doc/qt-5/qdir.html#Filter-enum. It is not an access function or anything.

      If you want to display all dirs inside a certain QDir, you need to iterate over QDir::entryList() or QDir::entryInfoList(), combined with a filter. Please see the documentation.

      (Z(:^

      1 Reply Last reply
      0
      • F Offline
        F Offline
        freesix
        wrote on 13 Aug 2014, 07:56 last edited by
        #3

        thanks.

        if I understand you, you meant there's no other way to do,
        and it always must be like I did in the above code?

        PS : Logic will get you from A to B, but Imagination will take you everywhere...

               Albert Einstein
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 13 Aug 2014, 08:02 last edited by
          #4

          There are always numerous ways to achieve a goal. I do not really understand what you are trying to do in your code, so I can't answer that question.

          (Z(:^

          1 Reply Last reply
          0
          • F Offline
            F Offline
            freesix
            wrote on 13 Aug 2014, 08:13 last edited by
            #5

            I wanted a code like this :

            @QMyVariable FirstVariable = mDir.count();

            QMyVariable SecondVariable = mDir.AllDirs;

            QDir mDir("C:/Windows/System32");
            
            foreach(QFileInfo mitm, mDir.entryList())
            {
                qDebug() << mitm.absoluteFilePath();
            }
            
            
            qDebug () <<"\nNumber of directories :" <<FirstVariable <<"items";
            
            qDebug () <<"\nNumber of files :" <<SecondVariable <<"items";
            

            @

            PS : Logic will get you from A to B, but Imagination will take you everywhere...

                   Albert Einstein
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 13 Aug 2014, 08:24 last edited by
              #6

              Mate, posting the same (wrong) code again does not help me understand your problem. So, I will be guessing what you mean.

              You want to print all files and directories in a folder, and then count them separately. Correct? This should work:

              @
              QDir mDir("C:/Windows/System32");
              qDebug() << mDir.entryList(QDir::Dirs | QDir::Files | QDir:NoDotAndDotDot);
              qDebug() << "Number of directories:" << mDir.entryList(QDir::Dirs).count();
              qDebug() << "Number of files:" << mDir.entryList(QDir::Files).count();
              @

              (Z(:^

              1 Reply Last reply
              0
              • F Offline
                F Offline
                freesix
                wrote on 13 Aug 2014, 11:21 last edited by
                #7

                okay, let me be explicit.

                The first code I posted on my first post is working GREAT, without any problem, you may also test it from your PC if you want; and my concern is not there !

                I might also use it as it's working fine, [ it doesn't a matter ] but I just want to use variable/constant in that code precisely in qDebug while displaying instead of directly using these enum value, like you called them.

                I'm going to reformulate my question :

                In accordance with the code that is on my first post, I need the result of "mDir.AllDirs" & "mDir.count()" to be saved in variables before displaying them through qDebug, and after using these variables through qDebug.

                PS : Logic will get you from A to B, but Imagination will take you everywhere...

                       Albert Einstein
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sierdzio
                  Moderators
                  wrote on 13 Aug 2014, 11:30 last edited by
                  #8

                  @
                  QDir::Filter myValue1 = mDir.AllDirs;
                  int myValue2 = mDir.count();
                  @

                  But I want to point it out again: AllDir value is an enum. It will not change to anything else, regardless of what you do to mDir variable. You can use QDir::AllDirs and it will have exactly the same effect, without the need to define an object (mDir).

                  (Z(:^

                  1 Reply Last reply
                  0

                  8/8

                  13 Aug 2014, 11:30

                  • Login

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