Results 1 to 5 of 5

Thread: Hi all, some about lists and views

  1. #1
    Join Date
    Jan 2011
    Location
    Gordion
    Posts
    52
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hi all, some about lists and views

    Qt Code:
    1. void MainWindow::FindLocalInterface()
    2. {
    3.  
    4.  
    5. foreach( QNetworkInterface interface, QNetworkInterface::allInterfaces() ){
    6. foreach( QNetworkAddressEntry addressEntry, interface.addressEntries() ){
    7.  
    8.  
    9.  
    10. ui->textEdit_2->append(( interface.humanReadableName()));
    11. ui->textEdit_2->append(( lookUpHost( QHostInfo::fromName( QHostAddress( addressEntry.ip() ).toString() ) ) ));
    12. ui->textEdit_2->append(( QHostAddress( addressEntry.ip() ).toString() ));
    13. ui->textEdit_2->append(( interface.hardwareAddress()));
    14. ui->textEdit_2->append(( QHostAddress( addressEntry.broadcast() ).toString()) );
    15. ui->textEdit_2->append(( QHostAddress( addressEntry.netmask() ).toString() ));
    16. ui->textEdit_2->append("\n\n\n");
    17.  
    18.  
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    Hi all, i have code like this. i want to see on a selectable item and select... i read treeview and table view manuals on my local but i cant find any good example and i need help. ):


    Added after 1 48 minutes:


    thanks for all...!
    Last edited by kosasker; 24th January 2011 at 11:23.

  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: Hi all, some about lists and views

    Hi,

    You can use a QComboBox.
    Then use addItem() to add an entry to it.
    Afterwards use currentIndex() and/or currentText() to get the item that is selected.

    Best regards,
    Marc

  3. #3
    Join Date
    Jan 2011
    Location
    Gordion
    Posts
    52
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hi all, some about lists and views

    Thanks for reply Sorry for my bad english. I solved it, and here is my code..


    Qt Code:
    1. void MainWindow::findLocal()
    2. {
    3. model = new QStandardItemModel();
    4. model->setHorizontalHeaderLabels( QStringList() << "Connection Name" <<"Computer Name"
    5. <<"IP Address" <<"MAC Address" <<"BroadCast" <<"Netmask");
    6.  
    7. ui->tableView->setModel(model);
    8.  
    9. QList<QStandardItem *> itemList;
    10.  
    11. // interfaces
    12. foreach( QNetworkInterface interface, QNetworkInterface::allInterfaces() ){
    13. foreach( QNetworkAddressEntry addressEntry, interface.addressEntries() ){
    14. itemList.clear();
    15. itemList << new QStandardItem( interface.humanReadableName());
    16. itemList << new QStandardItem( lookUpHost( QHostInfo::fromName( QHostAddress( addressEntry.ip() ).toString() ) ) );
    17. itemList << new QStandardItem( QHostAddress( addressEntry.ip() ).toString() );
    18. itemList << new QStandardItem( interface.hardwareAddress());
    19. itemList << new QStandardItem( QHostAddress( addressEntry.broadcast() ).toString() );
    20. itemList << new QStandardItem( QHostAddress( addressEntry.netmask() ).toString() );
    21. if (itemList.at(4)->text().isEmpty())
    22. {
    23. itemList.removeOne(itemList.at(itemList.count()));
    24. }
    25. model->appendRow( itemList );
    26. }
    27. }
    28.  
    29. }
    30.  
    31. QString MainWindow::lookUpHost(const QHostInfo &host)
    32. {
    33. if (host.error() != QHostInfo::NoError) {
    34. return "";
    35. }
    36.  
    37. return host.hostName();
    38. }
    To copy to clipboard, switch view to plain text mode 

    I have a one problem too... I cant remove empty items from item list. Its giving runtime error

  4. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Hi all, some about lists and views

    hi,

    I have a one problem too... I cant remove empty items from item list. Its giving runtime error
    what err u r getting?
    check line 21: if (itemList.at(4)->text().isEmpty())
    is at(4) is right?

    and also check itemList.removeOne(itemList.at(itemList.count()));


    hope it helpz
    Bala

  5. #5
    Join Date
    Jan 2011
    Location
    Gordion
    Posts
    52
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hi all, some about lists and views

    Ok. i solved this too with delete some lines

    Here is the code..

    Qt Code:
    1. if (!itemList.at(4)->text().isEmpty())
    2. model->appendRow( itemList );
    To copy to clipboard, switch view to plain text mode 

    Yes 4 is the true coloumn... When i looked up my interfaces, there is more then 10 interface is showing. But just one has a broadcast number. I just want only show the live interface and i did it....

    Thanks a lot

    Edit:

    Only connected interface's has a broadcast number... If you have more than 1 connection it will be listed..
    Last edited by kosasker; 24th January 2011 at 13:00.

Similar Threads

  1. diffrend kind of lists of GUI
    By tomixer in forum Qt Programming
    Replies: 7
    Last Post: 12th September 2010, 22:44
  2. display lists
    By rick_st3 in forum Newbie
    Replies: 3
    Last Post: 22nd June 2008, 23:09
  3. Some problems with lists
    By gdiepen in forum Qt Programming
    Replies: 9
    Last Post: 16th January 2008, 16:54
  4. When sort the lists?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2006, 16:30
  5. Array of linked lists
    By therealjag in forum General Programming
    Replies: 9
    Last Post: 9th March 2006, 18:36

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.