PDA

View Full Version : Hi all, some about lists and views



kosasker
24th January 2011, 11:23
void MainWindow::FindLocalInterface()
{


foreach( QNetworkInterface interface, QNetworkInterface::allInterfaces() ){
foreach( QNetworkAddressEntry addressEntry, interface.addressEntries() ){



ui->textEdit_2->append(( interface.humanReadableName()));
ui->textEdit_2->append(( lookUpHost( QHostInfo::fromName( QHostAddress( addressEntry.ip() ).toString() ) ) ));
ui->textEdit_2->append(( QHostAddress( addressEntry.ip() ).toString() ));
ui->textEdit_2->append(( interface.hardwareAddress()));
ui->textEdit_2->append(( QHostAddress( addressEntry.broadcast() ).toString()) );
ui->textEdit_2->append(( QHostAddress( addressEntry.netmask() ).toString() ));
ui->textEdit_2->append("\n\n\n");


}
}
}



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...!

marcvanriet
24th January 2011, 11:40
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

kosasker
24th January 2011, 12:32
Thanks for reply :) Sorry for my bad english. I solved it, and here is my code..




void MainWindow::findLocal()
{
model = new QStandardItemModel();
model->setHorizontalHeaderLabels( QStringList() << "Connection Name" <<"Computer Name"
<<"IP Address" <<"MAC Address" <<"BroadCast" <<"Netmask");

ui->tableView->setModel(model);

QList<QStandardItem *> itemList;

// interfaces
foreach( QNetworkInterface interface, QNetworkInterface::allInterfaces() ){
foreach( QNetworkAddressEntry addressEntry, interface.addressEntries() ){
itemList.clear();
itemList << new QStandardItem( interface.humanReadableName());
itemList << new QStandardItem( lookUpHost( QHostInfo::fromName( QHostAddress( addressEntry.ip() ).toString() ) ) );
itemList << new QStandardItem( QHostAddress( addressEntry.ip() ).toString() );
itemList << new QStandardItem( interface.hardwareAddress());
itemList << new QStandardItem( QHostAddress( addressEntry.broadcast() ).toString() );
itemList << new QStandardItem( QHostAddress( addressEntry.netmask() ).toString() );
if (itemList.at(4)->text().isEmpty())
{
itemList.removeOne(itemList.at(itemList.count()));
}
model->appendRow( itemList );
}
}

}

QString MainWindow::lookUpHost(const QHostInfo &host)
{
if (host.error() != QHostInfo::NoError) {
return "";
}

return host.hostName();
}



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

BalaQT
24th January 2011, 12:45
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

kosasker
24th January 2011, 12:55
Ok. i solved this too with delete some lines :)

Here is the code..



if (!itemList.at(4)->text().isEmpty())
model->appendRow( itemList );


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..