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. Application Crash when i call my function

Application Crash when i call my function

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 5 Posters 787 Views 2 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.
  • J Offline
    J Offline
    Jaber
    wrote on last edited by
    #1

    Hello everyone , i'm trying to get value from xml file using qt , so there is the xml file :

    <favorites>
      <server>
        <ip>127.0.0.1:7777</ip>
        <nickname></nickname>
        <password></password>
      </server>
      <server>
        <ip>127.1.1.1:7777</ip>
        <nickname>bdfjhd</nickname>
        <password></password>
      </server>
      <server>
        <ip>125.1.1.1:5445</ip>
        <nickname>fdkgfhfhf</nickname>
        <password></password>
      </server>
    </favorites>
    

    and this is my function :

    QString FavFile::GetFavListServers()
    {
        QFile file("favlist.xml");
        file.open(QIODevice::ReadOnly);
        QXmlStreamReader stream(&file);
    
        QString Ip;
        QString Name;
        QString Pass;
    
        try
        {
            while(stream.readNext() && !stream.isEndDocument())
            {
                if(stream.name() == "server")
                {
                    qDebug() << "server found";
    
                    while(stream.readNext() && !stream.isEndElement())
                    {
                        if(stream.name() == "ip")
                        {
                            Ip = stream.readElementText();
                        }
                        if(stream.name() == "nickname")
                        {
                            Name = stream.readElementText();
                        }
                        if(stream.name() == "password")
                        {
                            Pass = stream.readElementText();
                        }
                    }
                    qDebug() << "IP: " + Ip;
                }
            }
        }
        catch(QException &ex)
        {
            qDebug() << "Bug In try";
        }
    
        file.close();
    }
    

    The function work but app didn't responds ... there is some log :

    output :

    server found
    "IP: 127.0.0.1:7777"
    server found
    "IP: 127.1.1.1:7777"
    server found
    "IP: 125.1.1.1:5445"
    
    Le programme s'est terminé subitement . ---> crash 
    

    Debug :

    Signal name : 
    SIGSEGV
    Signal meaning : 
    Segmentation fault
    

    i think my loop didnt stop but i dont know why , thanks for help :)

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should get a stack trace. That will help pinpoint the problem.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      mrjjM 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        You should get a stack trace. That will help pinpoint the problem.

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

        hi
        with such short input u can also just single step it using debugger and see what go wrong.

        1 Reply Last reply
        1
        • J Jaber

          Hello everyone , i'm trying to get value from xml file using qt , so there is the xml file :

          <favorites>
            <server>
              <ip>127.0.0.1:7777</ip>
              <nickname></nickname>
              <password></password>
            </server>
            <server>
              <ip>127.1.1.1:7777</ip>
              <nickname>bdfjhd</nickname>
              <password></password>
            </server>
            <server>
              <ip>125.1.1.1:5445</ip>
              <nickname>fdkgfhfhf</nickname>
              <password></password>
            </server>
          </favorites>
          

          and this is my function :

          QString FavFile::GetFavListServers()
          {
              QFile file("favlist.xml");
              file.open(QIODevice::ReadOnly);
              QXmlStreamReader stream(&file);
          
              QString Ip;
              QString Name;
              QString Pass;
          
              try
              {
                  while(stream.readNext() && !stream.isEndDocument())
                  {
                      if(stream.name() == "server")
                      {
                          qDebug() << "server found";
          
                          while(stream.readNext() && !stream.isEndElement())
                          {
                              if(stream.name() == "ip")
                              {
                                  Ip = stream.readElementText();
                              }
                              if(stream.name() == "nickname")
                              {
                                  Name = stream.readElementText();
                              }
                              if(stream.name() == "password")
                              {
                                  Pass = stream.readElementText();
                              }
                          }
                          qDebug() << "IP: " + Ip;
                      }
                  }
              }
              catch(QException &ex)
              {
                  qDebug() << "Bug In try";
              }
          
              file.close();
          }
          

          The function work but app didn't responds ... there is some log :

          output :

          server found
          "IP: 127.0.0.1:7777"
          server found
          "IP: 127.1.1.1:7777"
          server found
          "IP: 125.1.1.1:5445"
          
          Le programme s'est terminé subitement . ---> crash 
          

          Debug :

          Signal name : 
          SIGSEGV
          Signal meaning : 
          Segmentation fault
          

          i think my loop didnt stop but i dont know why , thanks for help :)

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Jaber Isn't the crash somewhere else in your program, not in FavFile::GetFavListServers()?
          You should really just debug as suggested by others.

          One note: there is no need to concatenate string when using qDebug:

          qDebug() << "IP:" <<  Ip;
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5
            while(stream.readNext() && !stream.isEndElement())
                            {
                                if(stream.name() == "ip")
            

            Here you take for granted that stream.readNext() returned QXmlStreamReader::StartElement which is not the case as it can be on QXmlStreamReader::Characters

            "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

            1 Reply Last reply
            3

            • Login

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