Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. textdatei auslesen und zeile abfrage
Forum Updated to NodeBB v4.3 + New Features

textdatei auslesen und zeile abfrage

Scheduled Pinned Locked Moved Unsolved German
12 Posts 3 Posters 3.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.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 14 Apr 2019, 10:05 last edited by
    #2

    Hi
    Nur für die erste Zeile in der Datei?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      val78
      wrote on 14 Apr 2019, 10:08 last edited by val78
      #3

      nein
      jeder zeilen einzeiln abfragen

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 14 Apr 2019, 10:14 last edited by
        #4

        Hi
        ok, so etwas wie dieser code

        void ReadData()
        {
            QFile file("c:/PATHTO/thefile.txt");
            if (!file.open(QIODevice::ReadOnly)) {
                QMessageBox::information(nullptr, "error", file.errorString());
            }
            QTextStream in(&file);
            while (!in.atEnd()) {
                QString line = in.readLine();
                if (! line.isEmpty()  && line[0] == '#'  ) {
                    // it has #
                } else {
                    // kein #
                }
            }
        }
        
        1 Reply Last reply
        2
        • V Offline
          V Offline
          val78
          wrote on 14 Apr 2019, 10:38 last edited by
          #5

          kann mann einzeln zeilen abfragen ?
          z.B

          if 1 zeile
          if 2 zeile
          if 3 zeile 
          u.s.w
          
          A 1 Reply Last reply 14 Apr 2019, 10:44
          1
          • V val78
            14 Apr 2019, 10:38

            kann mann einzeln zeilen abfragen ?
            z.B

            if 1 zeile
            if 2 zeile
            if 3 zeile 
            u.s.w
            
            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 14 Apr 2019, 10:44 last edited by
            #6

            @val78 dazu müsstest Du die Datei zeilenweise in eine QStringList einlesen. Braucht natürlich dann soviel Speicher im RAM wie die Datei auf der Festplatte belegt.

            Qt has to stay free or it will die.

            1 Reply Last reply
            2
            • V Offline
              V Offline
              val78
              wrote on 14 Apr 2019, 11:10 last edited by
              #7

              ich brauche das für autostart

              um bestimmte programme bei start ein und auschalten
              autostart sied so aus

              mit # =  aus;   ohne  #= ein
              #xterm
              yakuake
              #xfce
              

              und das soll Buton steuern

              wenn  aus dann text "OFF" Button rot
              wenn ein dannn text "ON" Button grun
              

              und da sind mehrere zeilen mit oder ohne "#"

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 14 Apr 2019, 11:30 last edited by
                #8

                Hi
                Sie können eine Struktur in einer Liste verwenden,
                um sowohl den Namen als auch den Autostartstatus zu speichern

                struct AutoStartItem {
                    QString name;
                    bool autoStart = false;
                };
                
                QVector<AutoStartItem> AutoStartList; 
                
                void MainWindow::ReadData()
                {
                    QFile file("e:/auto.txt"); // change
                    if (!file.open(QIODevice::ReadOnly)) {
                        QMessageBox::information(nullptr, "error", file.errorString());
                    }
                    QTextStream in(&file);
                    AutoStartItem item;
                    while (!in.atEnd()) {
                        QString line = in.readLine();
                        if (! line.isEmpty()  && line[0] == '#'  ) {
                            // it has #
                            item.name = line.mid(1);
                            item.autoStart = true;
                        } else {
                            // kein #
                            item.name = line;
                            item.autoStart = false;
                        }
                        AutoStartList.append(item);
                    }
                
                    // list all
                    for (auto &item : AutoStartList ) {
                        qDebug()  << item.name <<  " start:" << item.autoStart;
                    }
                
                    // check one
                    if ( AutoStartList[3].autoStart ) qDebug()  << "Start it";
                }
                
                V 1 Reply Last reply 14 Apr 2019, 12:26
                2
                • M mrjj
                  14 Apr 2019, 11:30

                  Hi
                  Sie können eine Struktur in einer Liste verwenden,
                  um sowohl den Namen als auch den Autostartstatus zu speichern

                  struct AutoStartItem {
                      QString name;
                      bool autoStart = false;
                  };
                  
                  QVector<AutoStartItem> AutoStartList; 
                  
                  void MainWindow::ReadData()
                  {
                      QFile file("e:/auto.txt"); // change
                      if (!file.open(QIODevice::ReadOnly)) {
                          QMessageBox::information(nullptr, "error", file.errorString());
                      }
                      QTextStream in(&file);
                      AutoStartItem item;
                      while (!in.atEnd()) {
                          QString line = in.readLine();
                          if (! line.isEmpty()  && line[0] == '#'  ) {
                              // it has #
                              item.name = line.mid(1);
                              item.autoStart = true;
                          } else {
                              // kein #
                              item.name = line;
                              item.autoStart = false;
                          }
                          AutoStartList.append(item);
                      }
                  
                      // list all
                      for (auto &item : AutoStartList ) {
                          qDebug()  << item.name <<  " start:" << item.autoStart;
                      }
                  
                      // check one
                      if ( AutoStartList[3].autoStart ) qDebug()  << "Start it";
                  }
                  
                  V Offline
                  V Offline
                  val78
                  wrote on 14 Apr 2019, 12:26 last edited by
                  #9

                  @mrjj was ist AutoStartList
                  listView?

                  M 1 Reply Last reply 14 Apr 2019, 12:30
                  0
                  • V val78
                    14 Apr 2019, 12:26

                    @mrjj was ist AutoStartList
                    listView?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 14 Apr 2019, 12:30 last edited by mrjj
                    #10

                    @val78
                    Nein, nur eine normale Liste
                    QVector<AutoStartItem> AutoStartList;

                    V 1 Reply Last reply 14 Apr 2019, 14:05
                    0
                    • M mrjj
                      14 Apr 2019, 12:30

                      @val78
                      Nein, nur eine normale Liste
                      QVector<AutoStartItem> AutoStartList;

                      V Offline
                      V Offline
                      val78
                      wrote on 14 Apr 2019, 14:05 last edited by
                      #11

                      @mrjj was meinst du normale liste?

                      M 1 Reply Last reply 14 Apr 2019, 14:09
                      0
                      • V val78
                        14 Apr 2019, 14:05

                        @mrjj was meinst du normale liste?

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 14 Apr 2019, 14:09 last edited by mrjj
                        #12

                        @val78
                        Das ist kein Widget, sondern nur eine Liste mit den Daten.

                        (ps. Ich habe dein Level angehoben, damit du schneller antworten kannst.)

                        1 Reply Last reply
                        0

                        11/12

                        14 Apr 2019, 14:05

                        • Login

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