Results 1 to 6 of 6

Thread: Remove last item with QStingList

  1. #1
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Post Remove last item with QStingList

    Hello all,

    As always I turn to the experts. I have little time programming in Qt4 and I have yet a lot of documentation to review progress on my projects, but hey I guess that happened to us all.

    I have a problem not solve it.

    I have a list of this type 01000000000,02000000000,03000000000 defined with QStringList.
    The problem I have is that it removes the last element of the list 03000000000. If I've managed to eliminate the first and second but not the ulitmo. I require your knowledge to see if you can give me some solution, pq stand for two days with this nonsense, I know I'm clumsy.

    I leave part of the code to see if you can lend a hand to me.
    What I do is first find the total number of items in the list.
    Locate the item that interests me and that begins to erase 02.
    Delete the item.

    I tried to delete the item RemoveAt (), with removeLast, but if the item does not get ulitmo delete it.

    I leave the code and thank you very much for your help.


    ***************************************
    Qt Code:
    1. #define REGPATH_XXXXXXXX "HKEY_LOCAL_MACHINE\\SOFTWARE\\XXXXX"
    2. int TotalListaN;
    3. QStringList listOODelN;
    4. int PosicionOODelN=0;
    5. int IndiceOODelN=0;
    6. QString MostrarMensaje ="";
    7. QString sAplicacionesOODelN = settings::getRegAppInstaladas();
    8. int TotalElementosListaN = 0;
    9. int ntN=0;
    10. int IndiceOON2=0;
    11. int PosicionOON2=0;
    12.  
    13. QSettings settings(REGPATH_XXXXXXXX,QSettings::NativeFormat) ;
    14.  
    15. // listOODelN.sort();
    16.  
    17. if(sAplicacionesOODelN.size() > 0)
    18. {
    19. listOODelN = sAplicacionesOODelN.split(",");
    20. }
    21. QStringList::const_iterator constIteratorOODelN;
    22.  
    23. //Vamos a averiguar donde esta la cadena 02000 en la lista
    24. for (constIteratorOODelN = listOODelN.constBegin(); constIteratorOODelN != listOODelN.constEnd(); ++constIteratorOODelN){
    25.  
    26. TotalElementosListaN=ntN;
    27. }
    28.  
    29. int vListCount;
    30. vListCount = listOODelN.count();
    31. int i;
    32. bool encontrado(false);
    33. int PosicionLista=-1;
    34.  
    35. QMessageBox::information ( 0,"TOTAL ELEMENTOS LISTA", "El numero total de elementos en la lista es: "+QString::number(vListCount));
    36.  
    37. for (i=0; i
    38. {
    39. QMessageBox::information(0,"Contenido Lista i ", listOODelN[i],"Ok",0,0,0);
    40. QMessageBox::information ( 0,"Posicion Elemento", "La posicion en la lista es: "+QString::number(i));
    41.  
    42. if (listOODelN[i].startsWith("02")){
    43. PosicionOON2=i;
    44. encontrado=true;
    45. QMessageBox::information(0,"Encontrado Valor en Posicion :", QString::number(i));
    46. PosicionLista=i;
    47. }
    48.  
    49. }
    50.  
    51. int vListCountReal=vListCount-1;
    52. foreach (QString str, listOODelN) {
    53. //if (str.startsWith("02")){QMessageBox::information(0, "String Parser", listOODelN[i],"Ok",0,0,0);
    54. //QMessageBox::information(0,"VALORES A MOSTRAR:","Valor encontrado",QString::bool(encontrado));
    55. QMessageBox::information(0,"Total Valores Lista vlistcount :", QString::number(vListCount));
    56. QMessageBox::information(0,"Posicion en la lista PosicionLista:", QString::number(PosicionLista));
    57.  
    58. if (str.startsWith("02") && encontrado==true){
    59. if (PosicionLista=vListCountReal)
    60. {
    61. QMessageBox::information(0,"VALOR ENCONTRADO ","ENCONTRADO OK");
    62. QMessageBox::information(0,"valor a borrar ","Posicion Lista:", QString::number(PosicionLista), "vListCountReal:",QString::number(vListCount-1));
    63. listOODelN.append( );
    64. listOODelN.removeAt(PosicionLista);
    65. }else
    66. {
    67. PosicionOODelN=PosicionLista;
    68. QMessageBox::information(0,"ANTES DE BORRAR . POSICION EN LA LISTA",QString::number(PosicionOODelN));
    69. listOODelN.removeAt(PosicionOODelN);
    70. //QMessageBox::information(0,"DEBUG AGENTE",listOODel.at(PosicionOO));
    71. sAplicacionesOODelN = listOODelN.join(",");
    72. // QMessageBox::information(0,"BORRAMOS CONTENIDO LISTA",sAplicacionesOODel1);
    73. }
    74. }
    75. else {
    76. settings.setValue("Apl", sAplicacionesOODelN);
    77.  
    78. }
    79. IndiceOODelN++;
    80.  
    81. }
    82.  
    83. }//Fin Procedimiento BorrarContenidoListaOO()
    To copy to clipboard, switch view to plain text mode 

    ****************************************
    Last edited by wysota; 6th January 2012 at 02:37.

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Remove last item with QStingList

    Hi,

    Some comments :
    - use the QUOTE tags when you put code in a message
    - "ulitmo" is not an English word. What do you mean by that ?
    - your code would be easier to read for us if it contained English comments and function names
    - if you just dump a piece of code, pleas add comments as to where the part is that doesn't work

    removeLast(), removeAt() etc. all work without problems on a QStringList

    Qt Code:
    1. for (i=0; i
    2. {
    To copy to clipboard, switch view to plain text mode 

    This is clearly code that doesn't even compile. Only post real code.

    Regards,
    Marc

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,589
    Thanks
    13
    Thanked 1,585 Times in 1,514 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Remove last item with QStingList

    Quote Originally Posted by marcvanriet View Post
    - use the QUOTE tags when you put code in a message
    Even better, use the [code]...[/code] tags
    - "ulitmo" is not an English word. What do you mean by that ?
    I suspect it is mistyped "ultimo", Italian for "last".

  4. #4
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Remove last item with QStingList

    Hello all,

    Here's the source code. Now the comments are in English. I have not managed to remove the last item that is stored in the list.


    I hope you can help me.

    Thanks all


    #define REGPATH_XXXXXXXX "HKEY_LOCAL_MACHINE\\SOFTWARE\\XXXXX"
    int TotalListaN;
    QStringList listOODelN;
    int PosicionOODelN=0;
    int IndiceOODelN=0;
    QString MostrarMensaje ="";
    QString sAplicacionesOODelN = settings::getRegAppInstaladas();
    int TotalElementosListaN = 0;
    int ntN=0;
    int IndiceOON2=0;
    int PosicionOON2=0;

    QSettings settings(REGPATH_XXXXXXXX,QSettings::NativeFormat) ;



    if(sAplicacionesOODelN.size() > 0)
    {
    listOODelN = sAplicacionesOODelN.split(",");
    }
    QStringList::const_iterator constIteratorOODelN;

    //find String 02000 into the list
    for (constIteratorOODelN = listOODelN.constBegin(); constIteratorOODelN != listOODelN.constEnd(); ++constIteratorOODelN){

    TotalElementosListaN=ntN;
    }

    int vListCount;
    vListCount = listOODelN.count();
    int i;
    bool encontrado(false);
    int PosicionLista=-1;

    QMessageBox::information ( 0,"TOTAL LIST ELEMENTS", "The total elements into the list is: "+QString::number(vListCount));

    for (i=0; i
    {
    QMessageBox::information(0,"Content list i ", listOODelN[i],"Ok",0,0,0);
    QMessageBox::information ( 0,"Element Position", "The position into the list : "+QString::number(i));

    if (listOODelN[i].startsWith("02")){
    PosicionOON2=i;
    encontrado=true;
    QMessageBox::information(0,"Find value :", QString::number(i));
    PosicionLista=i;
    }

    }

    int vListCountReal=vListCount-1;
    foreach (QString str, listOODelN) {
    QMessageBox::information(0,"Total Elements into the list vlistcount :", QString::number(vListCount));
    QMessageBox::information(0,"Position List PosicionLista:", QString::number(PosicionLista));

    if (str.startsWith("02") && encontrado==true){
    if (PosicionLista=vListCountReal)
    {
    QMessageBox::information(0,"Value found ","FOUND OK");
    QMessageBox::information(0,"value delete ","Position List:", QString::number(PosicionLista), "vListCountReal:",QString::number(vListCount-1));
    listOODelN.append( );
    listOODelN.removeAt(PosicionLista);
    }else
    {
    PosicionOODelN=PosicionLista;
    QMessageBox::information(0,"before delete . LIST POSITION",QString::number(PosicionOODelN));
    listOODelN.removeAt(PosicionOODelN);

    sAplicacionesOODelN = listOODelN.join(",");

    }
    }
    else {
    settings.setValue("Apl", sAplicacionesOODelN);

    }
    IndiceOODelN++;

    }

    }

  5. #5
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Remove last item with QStingList

    Use the CODE tags
    Qt Code:
    1. for (i=0; i
    2. {
    To copy to clipboard, switch view to plain text mode 
    Only post real code. The above is just blatently wrong.

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    859
    Thanks
    69
    Thanked 57 Times in 55 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove last item with QStingList

    Hi,

    Explain us in a better way what is your problem.
    I'm not able to understand if you have a QStringList with only one element "01000000000,02000000000,03000000000", or this QStringList contains three elements,...
    If you have a QStringList with N elements you can remove the last element using QStringList::removeLast() method.
    Òscar Llarch i Galán

Similar Threads

  1. Replies: 0
    Last Post: 1st October 2010, 16:09
  2. Remove an item
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 16th September 2009, 08:47
  3. How to use QMap::remove() to delete some item?
    By jedychen in forum Qt Programming
    Replies: 5
    Last Post: 18th September 2008, 08:29
  4. QListWidgetItem remove an item
    By mattia in forum Newbie
    Replies: 4
    Last Post: 9th November 2007, 08:57
  5. remove item from QListWidget
    By yushinee in forum Newbie
    Replies: 3
    Last Post: 2nd October 2007, 21:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.