Domanda

I have some part of code with which the debugger , when entering , starts stopping in lines with { braces.. suddenly jumps back to a blank line, and apparently is doing something (variables change), but the positions are different (there is some kind of weird offset back, skipping blank lines) and obviously i cannot see the contents of any variable.

Some facts:

  • I'm compiling on DEBUG
  • The code that fails falls inside more code which executes perfectly before.
  • The code does not work properly, but i double checked and it should. They are just 10 lines of code, exactly the same lines that the ones before, just changing variables names.
  • The debugguer stays crazy there, then out of the function in the caller function, and then returns to a normal state in the third parent function.
  • This code uses Qt 4.7 and QDomDocument functionality but works perfectly on other parts of the code. I added it to precompiled headers. (QXML)

I tried these with same errors:

  • Cleaning solution by hand or by visual
  • Cleaning all related Qt files (moc). Removed them, recompile, add again.
  • Changed the function to other part of the class.
  • Changed that piece of code to other part of the function.
  • Deleted file, removed from folder, compile, add it again and include the MOC.
  • Checked other threads. It is on the good thread.

Commenting the code makes it work perfect.

Here's the cursed code:

(...loaded file, check if worked)

// Assign file to dom document
  QDomDocument doc("XML");
  if (!doc.setContent(file))  {
    file->close();
    return;
  }

  // Root element (object)
  QDomElement root = doc.documentElement();

  QDomElement elt;
  QDomElement elt2;
  QDomElement elt3;

  // NAME
  elt = root.firstChildElement("name");  //-- works and debugs ok
  if (!elt.isNull())
    obj->setNameInfo(elt.text());

  // TYPE
  elt = root.firstChildElement("type"); //-- works and debugs ok
  if (!elt.isNull())
    obj->setTypeInfo(elt.text());

  // REF NUMBER
  elt = root.firstChildElement("ref"); //-- works and debugs ok
  if (!elt.isNull())
    obj->setRefNumberInfo( elt.text() );

  // COLLECTION <collection><english>Text</english>...

  elt = root.firstChildElement("collection"); //-- works and debugs ok
  if (!elt.isNull())
  {
    elt2 = elt.firstChildElement("english");
    if (!elt2.isNull())
      obj->setCollectionInfo( elt2.text() );
  }

  // BRAND <mainBrand><id>id</id><web>url</web></brand>

  elt = root.firstChildElement("mainBrand"); //-- works and debugs ok
  if (!elt.isNull())
  {
    elt2 = elt.firstChildElement("id");
    if (!elt2.isNull())
      obj->setMainBrandIdInfo(elt2.text());

    elt2 = elt.firstChildElement("web");
    if (!elt2.isNull())
      obj->setMainBrandUrlInfo(elt2.text());
  }


  // BRAND LIST   <brands><brand><id>2</id><url>google</url></brand>...</brands>

  elt = root.firstChildElement("brands");  
  {
    QDomNodeList brands = elt.childNodes();  // AFTER THIS LINE, STARTS GOING WEIRD
    if ( ! brands.isEmpty() )                
    {
      elt2 = brands.at(0).toElement();
      for ( ; !elt2.isNull(); elt2 = elt2.nextSiblingElement() ) 
      {
        QString id= "";
        elt3 = elt2.firstChildElement("id");
        if (!elt3.isNull()) 
          id = elt3.text();

        QString url= "";
        elt3 = elt2.firstChildElement("url");
        if (!elt3.isNull()) 
          url = elt3.text();

        obj->addBrandInfo(id, url);
      }
    }
  }

  // DESCRIPTION   // THIS IS EXECUTED PERFECTLY BUT DEBUGGER IS STILL JUMPING AROUND
  elt = root.firstChildElement("description"); 
  if (!elt.isNull())
  {
    elt2 = elt.firstChildElement("english");
    if (!elt2.isNull())
      obj->setDescriptionInfo( elt2.text() );
  }

  ... MORE CODE HERE. UNTIL THE END THE DEBUGGER WORKS WITH SOME WEIRD OFSET... 
È stato utile?

Soluzione

I discovered the answer after long hours of trials:

Reading the dissasembling of the code, we detected that Comment lines generated code, lines were not in the correct place, etcetera.

The problem comes with the encoding of the line breaks. The encoding of the file was not WINDOWS encoding. We had this set like this because we worked with MAC configurations, and we had some error messages concerning line breaks style. We choose one encoding that didn't fail since then, but now this error appeared.

The solution is to Save As... the file, selecting other options for the saving, and choose change encoding to Windows or whatever encoding you want to use.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top