Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Ayuda con un bucle xD

    Spanish
    2
    3
    919
    Loading More Posts
    • 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.
    • T
      tonismr1 last edited by

      Buenas a todos! necesito ayuda con una función que estoy haciendo, bien esta funcion lee linea a linea un fichero de configuracion, hasta aqui todo bien el problema que tengo, es al querer leer una de esas lineas, caracter por caracter (ya que solo necesito unos datos del medio de la linea). Bien la cosa es que creo un bucle for para leer esa linea caracter por caracter, esto tambien lo hace bien pero yo necesito que dentro de ese for tenga una condicion y es que cuando el caracter sea uno especifico ("#") empiece a meter los datos desde ese carcater hasta un maximo de 6 en una variable.

      El programa compila bien sin dar ningun error, pero el bucle lo salta...

      Gracias por vuestro tiempo!

      Mirar aqui esta el bucle que digo:
      @
      if(line.contains("menu color title"))
      {

              qDebug() << line; // Aqui me aseguro que la linea esta completa y no falla
              int activador;
              int contador;
              for(int i; i < line.size(); ++i)
              {
                  qDebug() << line.at(i); 
      

      // Si quito estas condiciones el bucle funciona bien me va sacando caracter x caracter

                  if(line.at(i) == QChar('#'))
                  {
                    activador = 1;
                    qDebug() << line.at(i);
                  }
                  if((activador == 1) && (contador <= 5))
                  {
                      title_color = title_color + line.at(i);
                      qDebug() << line.at(i);
                      contador++;
                  }
      
              }
      

      }
      @

      Por si fuese necesiario os dejo la funcion completa:
      @
      void MainWindow::READ_MENU(QString directory_root)
      {
      qDebug() << "READ FILE : " << directory_root << "/syslinux.cfg";
      QFile file(directory_root + "/syslinux.cfg");
      if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
      return;
      QTextStream in(&file);
      while(!in.atEnd())
      {
      QString line = in.readLine();
      if(line.contains("menu title"))
      {
      line.replace(0, 10, "");
      title = line;
      qDebug() << "MENU TITLE : " << line;
      }
      if(line.contains("menu background"))
      {
      line.replace(0, 16, "");
      background = directory_root + "/" + line;
      qDebug() << "MENU BACKGROUND : " << line;
      }
      if(line.contains("MENU TABMSG "))
      {
      line.replace(0, 12, "");
      TABMSG = line;
      qDebug() << "MENU tabmsg : " << line;
      }

          if(line.contains("menu color title"))
          {
      
              qDebug() << line;
              int activador;
              int contador;
              for(int i; i < line.size(); ++i)
              {
                  qDebug() << line.at(i);
                  if(line.at(i) == QChar('#'))
                  {
                    activador = 1;
                    qDebug() << line.at(i);
                  }
                  if((activador == 1) && (contador <= 5))
                  {
                      title_color = title_color + line.at(i);
                      qDebug() << line.at(i);
                     contador ++;
                  }
      
              }
          }
      
      
      }
      
      qDebug() << test;
      

      }
      @

      1 Reply Last reply Reply Quote 0
      • E
        EngLucas last edited by

        You should initialize the "contador" variable.

        int contador = 0;

        1 Reply Last reply Reply Quote 0
        • E
          EngLucas last edited by

          And also, inialize the loop variable.

          int i = 0;

          1 Reply Last reply Reply Quote 0
          • First post
            Last post