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

textdatei auslesen und zeile abfrage

Scheduled Pinned Locked Moved Unsolved German
12 Posts 3 Posters 4.3k 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.
  • V Offline
    V Offline
    val78
    wrote on last edited by val78
    #3

    nein
    jeder zeilen einzeiln abfragen

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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 last edited by
        #5

        kann mann einzeln zeilen abfragen ?
        z.B

        if 1 zeile
        if 2 zeile
        if 3 zeile 
        u.s.w
        
        aha_1980A 1 Reply Last reply
        1
        • V val78

          kann mann einzeln zeilen abfragen ?
          z.B

          if 1 zeile
          if 2 zeile
          if 3 zeile 
          u.s.w
          
          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 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 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
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              2
              • mrjjM mrjj

                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 last edited by
                #9

                @mrjj was ist AutoStartList
                listView?

                mrjjM 1 Reply Last reply
                0
                • V val78

                  @mrjj was ist AutoStartList
                  listView?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #10

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

                  V 1 Reply Last reply
                  0
                  • mrjjM mrjj

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

                    V Offline
                    V Offline
                    val78
                    wrote on last edited by
                    #11

                    @mrjj was meinst du normale liste?

                    mrjjM 1 Reply Last reply
                    0
                    • V val78

                      @mrjj was meinst du normale liste?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 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

                      • Login

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