Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Spanish
  4. Ayuda con un bucle xD
Forum Updated to NodeBB v4.3 + New Features

Ayuda con un bucle xD

Scheduled Pinned Locked Moved Spanish
3 Posts 2 Posters 1.2k 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.
  • T Offline
    T Offline
    tonismr1
    wrote on last edited by
    #1

    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
    0
    • E Offline
      E Offline
      EngLucas
      wrote on last edited by
      #2

      You should initialize the "contador" variable.

      int contador = 0;

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EngLucas
        wrote on last edited by
        #3

        And also, inialize the loop variable.

        int i = 0;

        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