Results 1 to 9 of 9

Thread: Help with QTreeWidget list of contacts XMPP

  1. #1
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question Help with QTreeWidget list of contacts XMPP

    Hi i am trying to do one project like webrtc but in small. In this chat i will have users connected and offline. I tried to do one easy example with QTreeWidget still i'm trying to solve this issue. My problem is when i add a new contact in my account, the contact old is deleted and the new is created. The problem is when i add the child.
    Code:
    Qt Code:
    1. logado = true; //contacts
    2. ui->frameLogin->show();
    3. ui->frameConexion->show();
    4. int i,j;
    5. QStringList contactos = cliente.rosterManager().getRosterBareJids();
    6. for(i=0;i<contactos.length();i++)
    7. {
    8. item->setText(0,contactos[i]);
    9. QStringList recursos = cliente.rosterManager().getResources(contactos[i]);
    10. QIcon online;
    11. online.addFile(":/icons/user-offline.png");
    12. item->setIcon(0,online);
    13. for(j=0;j<recursos.length();j++)
    14. {
    15. item->addChild(item);
    16. item->child(j)->setText(0,recursos[j]);
    17. online.addFile(":/icons/user-online.png");
    18. item->setIcon(0,online);
    19. item->child(j)->setIcon(0,online);
    20.  
    21.  
    22. }
    23. listaItems.append(item);
    24. }
    25. ui->arbolConectados->addTopLevelItems(listaItems);
    To copy to clipboard, switch view to plain text mode 
    Any idea is good. It's only in the child doesnt add me one child insted of create me a new child and delete me the old.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with QTreeWidget list of contacts XMPP

    Line 16 looks wrong, you are adding "item" to itself.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Help with QTreeWidget list of contacts XMPP

    Ok i edited the code. The code was very wrong.
    But i have one little question sorry again! But it's possible to add one item of my qtreewidget in my list??????

    Actual code:
    Qt Code:
    1. void MainWindow::rosterRecibido()
    2. {
    3. logado = true; //cuando recibimos el roster ya mostramos el frame con la lista de conectados
    4. ui->frameLogin->hide();
    5. ui->frameConexion->show();
    6. int i,j;
    7. QStringList contactos = cliente.rosterManager().getRosterBareJids();
    8. QList<QString> listaItems;
    9. for(i=0;i<contactos.length();i++)
    10. {
    11. item->setText(0,contactos[i]);
    12. QStringList recursos = cliente.rosterManager().getResources(contactos[i]);
    13. QIcon online;
    14. online.addFile(":/icons/user-offline.png");
    15. item->setIcon(0,online);
    16. for(j=0;j<recursos.length();j++)
    17. {
    18. AddChild(item);
    19. listaItems.append(item);
    20. }
    21. ui->arbolConectados->addTopLevelItems(listaItems);
    22. }
    23. }
    24.  
    25. void MainWindow::AddChild(QTreeWidgetItem *parent){
    26. parent->addChild(item);
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 


    Added after 4 minutes:


    I want in the before code to include items of my QTreeWidget in my list. And here resize the content that i will show.
    And this code is when i show the content:
    Qt Code:
    1. void MainWindow::cambioRoster(QString barejid, QString resource)
    2. {
    3. if(cliente.rosterManager().isRosterReceived() == true)
    4. {
    5. QIcon online;
    6. online.addFile(":/icons/user-online.png");
    7. if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly).size() == 0)
    8. {
    9. item->setText(0,barejid);
    10. ui->arbolConectados->addTopLevelItem(item);
    11. }
    12. if(cliente.rosterManager().getPresence(barejid,resource).type() == QXmppPresence::Available)
    13. {
    14. item->setText(0,resource);
    15. item->setIcon(0,online);
    16. ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->addChild(item);
    17. }
    18. if(cliente.rosterManager().getPresence(barejid,resource).type() == QXmppPresence::Unavailable)
    19. {
    20. int i=0;
    21. while(i<ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->childCount() && ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->child(i)->text(0) != resource) //busqueda lineal
    22. {
    23. i++;
    24. }
    25. ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->takeChild(i);
    26. if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->childCount() == 0)
    27. {
    28. online.addFile(":/icons/user-offline.png");
    29. }
    30. }
    31. ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->setIcon(0,online);
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by SirJonas; 15th October 2016 at 11:49.

  4. #4
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Help with QTreeWidget list of contacts XMPP

    Basically my question is when i show my index rosterRecibido(), all time show me one item. I add my items to one list and show them. So i want to show more items. You can check code. I updated to add child but not get the thing that i am trying.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with QTreeWidget list of contacts XMPP

    Your code is very weird.

    For example in rosterRecibido() you iterate over "contactos", yet you only ever use the same item.
    The inner loop creates empty items for not apparent reason.

    Your code in cambioRoster() does a lot of findItems() calls. Probably OK, but still very wastful.

    Cheers,
    _

  6. #6
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Help with QTreeWidget list of contacts XMPP

    message duplicated*
    Last edited by davinciomare; 15th October 2016 at 18:17.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with QTreeWidget list of contacts XMPP

    Well, if you want to have separate items for each entry in contactos, then I suggest you do that.
    Currently you are just setting new data on the single item you have.

    The inner loop also makes no sense: if creates a number of children for "item" but again and again adds that very same "item" to a list.

    Cheers,
    _

  8. #8
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Help with QTreeWidget list of contacts XMPP

    i did so because the item heridate of father so will have the same features for example. In the cambioRoster() because i will three differents, Available, Unavailable and the first the size. But you are right i think i can show content of my qtreeview without repeat a lot of times the same thing.

    This is the code:
    Qt Code:
    1. void MainWindow::cambioRoster(QString barejid, QString resource)
    2. {
    3. if(cliente.rosterManager().isRosterReceived() == true)
    4. {
    5. QIcon online;
    6. online.addFile(":/icons/user-online.png");
    7. if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly).size() == 0)
    8. {
    9. item->setText(0,barejid);
    10. ui->arbolConectados->addTopLevelItem(item);
    11. }
    12. if(cliente.rosterManager().getPresence(barejid,resource).type() == QXmppPresence::Available)
    13. {
    14. item->setText(0,resource);
    15. item->setIcon(0,online);
    16. ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->addChild(item);
    17. }
    18. if(cliente.rosterManager().getPresence(barejid,resource).type() == QXmppPresence::Unavailable)
    19. {
    20. int i=0;
    21. while(i<ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->childCount() && ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->child(i)->text(0) != resource) //busqueda lineal
    22. {
    23. i++;
    24. }
    25. ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->takeChild(i);
    26. if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->childCount() == 0)
    27. {
    28. online.addFile(":/icons/user-offline.png");
    29. }
    30. }
    31. ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->setIcon(0,online);
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 


    Added after 5 minutes:


    for example when i try change the size of items finded show me this error:
    https://i.imgsafe.org/13d50793d8.png

    why skoda?
    Last edited by SirJonas; 15th October 2016 at 18:40.

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with QTreeWidget list of contacts XMPP

    Quote Originally Posted by SirJonas View Post
    for example when i try change the size of items finded show me this error:
    https://i.imgsafe.org/13d50793d8.png
    You are apparently accessing a QList with an index that is not valid for that list.

    Cheers,
    _

Similar Threads

  1. Error again with xmpp in qt 5.2
    By davinciomar in forum Newbie
    Replies: 12
    Last Post: 28th August 2016, 00:19
  2. Replies: 1
    Last Post: 18th May 2011, 10:18
  3. how to display QTreewidget like list
    By sudhansu in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2011, 11:15
  4. List all elements of a QTreeWidget from top to bottom
    By ricardosf in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2010, 02:46
  5. Cursor is not moving through QTreeWidgetItem list in QTreeWidget
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2009, 06:52

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.