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. iterator.next().contains("service") doesn't work properly
Forum Updated to NodeBB v4.3 + New Features

iterator.next().contains("service") doesn't work properly

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 326 Views
  • 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.
  • J Offline
    J Offline
    jakubiszon26
    wrote on last edited by
    #1

    HI i'm trying to show in my list widget only files that ends with .service.
    i made this:

    QDirIterator iterator("/lib/systemd/system/");
       ui->servicesList->clear();
       while(iterator.hasNext()){
           if(!iterator.next().contains("service")){
               return;
           }
           ui->servicesList->addItem(iterator.next());
       }
    

    but in my list i can see positions with .target and .socket do you know what's wrong? thanks

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #3
      QDirIterator iterator("/lib/systemd/system/");
         ui->servicesList->clear();
         while(iterator.hasNext()){
             const auto current = iterator.next();
             if(current.contains("service"))
             ui->servicesList->addItem(current );
         }
      

      "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

      J 1 Reply Last reply
      3
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #2

        @jakubiszon26 said in iterator.next().contains("service") doesn't work properly:

        iterator.next()

        According to the documentation: "Advances the iterator to the next entry, and returns the file path of this new entry. "

        return;

        this is wrong I would guess

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #3
          QDirIterator iterator("/lib/systemd/system/");
             ui->servicesList->clear();
             while(iterator.hasNext()){
                 const auto current = iterator.next();
                 if(current.contains("service"))
                 ui->servicesList->addItem(current );
             }
          

          "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

          J 1 Reply Last reply
          3
          • VRoninV VRonin
            QDirIterator iterator("/lib/systemd/system/");
               ui->servicesList->clear();
               while(iterator.hasNext()){
                   const auto current = iterator.next();
                   if(current.contains("service"))
                   ui->servicesList->addItem(current );
               }
            
            J Offline
            J Offline
            jakubiszon26
            wrote on last edited by
            #4

            @VRonin thanks a lot.

            1 Reply Last reply
            1

            • Login

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