# class ServiceModel

###

Module | dnssd
Namespace | DNSSD
Class | ServiceModel
Inherits | QAbstractItemModel

\class ServiceModel servicemodel.h DNSSD/ServiceModel

ServiceModel implements Qt Model interface around ServiceBrowser to allow easy integration of service discovery into GUI. Example of combo box showing list of HTTP servers on local network:

    DNSSD.ServiceModel* m=new ServiceModel(new DNSSD.ServiceBrowser("_http._tcp"));
    QComboBox *c=new QComboBox();
    c->setModel(m);

After user makes the selection, application typically needs pointer to selected service in order to get host name and port. RemoteService.Ptr can be obtained from QModelIndex using:

    void onSelected(const QModelIndex& selection) {
    DNSSD.RemoteService.Ptr service=selection.data(DNSSD.ServiceModel.ServicePtrRole).
    value<DNSSD.RemoteService.Ptr>();

\since 4.1 Model for list of Zeroconf services Author Jakub Stachowski

### enums

- AdditionalRoles { ServicePtrRole }
- ModelColumns { ServiceName, Host, Port }

enum details

### methods

- ServiceModel (browser, parent)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  browser | DNSSD.ServiceBrowser |
  parent | QObject | 0

  Creates model for given service browses and starts browsing for services. The model becomes parent of the browser so there is no need to delete it afterwards.

- columnCount (parent)

  returns int

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex | QModelIndex()

- data (index, role)

  returns QVariant

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |
  role | int | Qt.DisplayRole

- hasIndex (row, column, parent)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  row | int |
  column | int |
  parent | QModelIndex |

- headerData (section, orientation, role)

  returns QVariant

  Argument | Type | Default
  --- | --- | ---
  section | int |
  orientation | Qt.Orientation |
  role | int | Qt.DisplayRole

- index (row, column, parent)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  row | int |
  column | int |
  parent | QModelIndex | QModelIndex()

- parent (index)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |

- rowCount (parent)

  returns int

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex | QModelIndex()

### enums - detail

- AdditionalRoles { ServicePtrRole }

  | ServicePtrRole | - 0xA06519DE | - |

- ModelColumns { ServiceName, Host, Port }

  Default columns for this model. If service browser is not set to resolve automatically, then the model has only one column (service name).

  | ServiceName | - 0 | - |
  | Host | - 1 | - |
  | Port | - 2 | - |