What I have is a listview, to show list of contacts. There is one model for that listview, a search box and also a label. Whenever the user enters text in the search box, to filter the contacts based on the text typed in the search box.
Here is my code
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import Qt 4.7
import QtMobility.contacts 1.1
Rectangle {
property QtObject blah: con
width: 360
height: 640
ListView
{
anchors.top:searchbox.bottom
height: parent.height
width: parent.width
id: _ListViews
model:ContactModel{
filter: DetailFilter {
id:filter
detail:ContactDetail.Name
field:Name.FirstName
value:searchbox.searchtext
matchFlags:Filter.MatchStartsWith
}
sortOrders: SortOrder{
detail: ContactDetail.Name
field:Name.FirstName
direction: Qt.AscendingOrder
}
}
delegate: Rectangle{
width: parent.width
height:50
Item {
Column{
Text {
id: name
text: model.contact.displayLabel
}
}
}
}
}
SearchBox{
id: searchbox
visible: true
}
}
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import Qt 4.7
import QtMobility.contacts 1.1
Rectangle {
property QtObject blah: con
width: 360
height: 640
ListView
{
anchors.top:searchbox.bottom
height: parent.height
width: parent.width
id: _ListViews
model:ContactModel{
filter: DetailFilter {
id:filter
detail:ContactDetail.Name
field:Name.FirstName
value:searchbox.searchtext
matchFlags:Filter.MatchStartsWith
}
sortOrders: SortOrder{
detail: ContactDetail.Name
field:Name.FirstName
direction: Qt.AscendingOrder
}
}
delegate: Rectangle{
width: parent.width
height:50
Item {
Column{
Text {
id: name
text: model.contact.displayLabel
}
}
}
}
}
SearchBox{
id: searchbox
visible: true
}
}
To copy to clipboard, switch view to plain text mode
whenever i type a letter i get the error
TypeError: Result of expression 'model.contact' [undefined] is not an object.
if there are no matches in the contact list the app crashes
Now I need to display nothing found in the list view, when there are no matches in the list. How to achieve that.?
Bookmarks