I use Qt version 5.5.1 with qml from windows 8.1 and multi webcam in my project.
which connect to computer with USB. how can I detect disconnecting webcam?
I use some signal of webcam in my program like onAvailabilityChanged and onCameraStatusChanged , ... .But after disconnection of camera I do not see any log.
please guide me.
thanks

Qt Code:
  1. import QtQuick 2.3
  2. import QtQuick.Controls 1.2
  3.  
  4. import QtMultimedia 5.5
  5.  
  6. ApplicationWindow {
  7. visible: true
  8. width: 640
  9. height: 480
  10.  
  11. title: qsTr("Hello World")
  12.  
  13. Item {
  14. width: parent.width
  15. height: parent.height
  16.  
  17. Camera {
  18. id: camera
  19.  
  20. imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
  21.  
  22. exposure {
  23. exposureCompensation: -1.0
  24. exposureMode: Camera.ExposurePortrait
  25. }
  26.  
  27. flash.mode: Camera.FlashRedEyeReduction
  28.  
  29. imageCapture {
  30. onImageCaptured: {
  31. photoPreview.source = preview // Show the preview in an Image
  32. }
  33. onCaptureFailed: {
  34. console.log("Camera disconnect");
  35. }
  36.  
  37. }
  38.  
  39. onAvailabilityChanged: {
  40. if(camera.availability!=Camera.Available)
  41. {
  42. console.log("Camera disconnect");
  43. }
  44. }
  45.  
  46. onCameraStateChanged: {
  47. if(camera.cameraState==Camera.UnloadedStatus){
  48. console.log("Camera disconnect nedaaa");
  49. }
  50. }
  51.  
  52. onCameraStatusChanged: {
  53. if(camera.cameraStatus!=Camera.ActiveStatus){
  54. console.log("Camera disconnect");
  55. }
  56.  
  57.  
  58. if (cameraStatus == Camera.ActiveStatus) {
  59.  
  60. var fr = camera.supportedViewfinderFrameRateRanges();
  61. fpsList.model = fr;
  62.  
  63.  
  64. var res = camera.supportedViewfinderResolutions();
  65. resolutionList.model = res;
  66. }
  67. }
  68.  
  69. onError: {
  70. camera.unlock();
  71. console.error("error: " + camera.errorString);
  72. }
  73.  
  74. }
  75.  
  76.  
  77. VideoOutput {
  78. id: viewfinder
  79. source: camera
  80. anchors.fill: parent
  81. focus : visible
  82.  
  83. }
  84.  
  85. Image {
  86. id: photoPreview
  87. }
  88.  
  89.  
  90. Row{
  91.  
  92. Rectangle {
  93. width: 200
  94. height: 200
  95. id: frame
  96.  
  97. color: "green"
  98. ListView {
  99. id:fpsList
  100. height: 200
  101. width:200
  102.  
  103. snapMode:ListView.SnapOneItem
  104. highlightRangeMode :ListView.ApplyRange
  105. highlight: Rectangle { color: "red"; radius: 5 }
  106. delegate: Item {
  107. height: 40
  108. width:200
  109. Text {
  110. text: modelData.minimumFrameRate +" x "+modelData.maximumFrameRate
  111.  
  112. anchors.fill: parent
  113. anchors.margins: 5
  114. horizontalAlignment: Text.AlignHCenter
  115. verticalAlignment: Text.AlignVCenter
  116. elide: Text.ElideRight
  117. color: "white"
  118. font.bold: true
  119. style: Text.Raised
  120. styleColor: "black"
  121. font.pixelSize: 14
  122. }
  123. MouseArea {
  124. anchors.fill: parent
  125. onClicked: {
  126. camera.viewfinder.minimumFrameRate = modelData.minimumFrameRate;
  127. camera.viewfinder.maximumFrameRate = modelData.maximumFrameRate;
  128. fpsList.currentIndex = index;
  129. }
  130. }
  131. Component.onCompleted: {
  132. if ((modelData.minimumFrameRate == camera.viewfinder.minimumFrameRate) && (modelData.maximumFrameRate == camera.viewfinder.maximumFrameRate)) {
  133. fpsList.currentIndex = index;
  134. }
  135. }
  136. }
  137. add: Transition {
  138. NumberAnimation { properties: "x,y"; from: 100; duration: 1000 }
  139. }
  140. addDisplaced: Transition {
  141. NumberAnimation { properties: "x,y"; duration: 1000 }
  142. }
  143. displaced: Transition {
  144. NumberAnimation { properties: "x,y"; duration: 1000 }
  145. }
  146. }
  147.  
  148. }
  149.  
  150. Rectangle {
  151. width: 200
  152. height: 200
  153. id: hhh
  154.  
  155. color: "blue"
  156. ListView {
  157. id:cameraList
  158. model: QtMultimedia.availableCameras
  159. height: 200
  160. width:200
  161. snapMode:ListView.SnapOneItem
  162. highlightRangeMode :ListView.ApplyRange
  163. highlight: Rectangle { color: "red"; radius: 5 }
  164. delegate: Item {
  165. height: 40
  166. width:200
  167. Text {
  168. text: modelData.displayName
  169. anchors.fill: parent
  170. anchors.margins: 5
  171. horizontalAlignment: Text.AlignHCenter
  172. verticalAlignment: Text.AlignVCenter
  173. elide: Text.ElideRight
  174. color: "white"
  175. font.bold: true
  176. style: Text.Raised
  177. styleColor: "black"
  178. font.pixelSize: 14
  179. }
  180.  
  181. MouseArea {
  182. anchors.fill: parent
  183. onClicked: {
  184. cameraList.currentIndex = index
  185. camera.deviceId = modelData.deviceId
  186. //cameraList.selected(modelData.deviceId)
  187. }
  188. }
  189. Component.onCompleted: {
  190. if (modelData.displayName === camera.displayName) {
  191. cameraList.currentIndex = index;
  192. }
  193. }
  194. }
  195. add: Transition {
  196. NumberAnimation { properties: "x,y"; from: 100; duration: 1000 }
  197. }
  198. addDisplaced: Transition {
  199. NumberAnimation { properties: "x,y"; duration: 1000 }
  200. }
  201. displaced: Transition {
  202. NumberAnimation { properties: "x,y"; duration: 1000 }
  203. }
  204. }
  205.  
  206. }
  207.  
  208. Rectangle {
  209. height: 200
  210. width:200
  211. color: "yellow"
  212.  
  213. ListView {
  214. id:resolutionList
  215. height: 200
  216. width:200
  217. highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
  218. snapMode:ListView.SnapOneItem
  219. highlightRangeMode :ListView.ApplyRange
  220. delegate: Item {
  221. height: 40
  222. width:200
  223. Text {
  224. color:"green"
  225. text: modelData.width + "x" + modelData.height
  226. MouseArea {
  227. anchors.fill: parent
  228. onClicked: {
  229.  
  230. camera.stop();
  231. camera.viewfinder.resolution = Qt.size(modelData.width, modelData.height);
  232. camera.start();
  233. resolutionList.currentIndex = index;
  234. }
  235. }
  236. }
  237. Component.onCompleted: {
  238. if ((modelData.height == camera.viewfinder.resolution.height) && (modelData.width == camera.viewfinder.resolution.width)) {
  239. resolutionList.currentIndex = index;
  240. }
  241. }
  242. }
  243. }
  244.  
  245. }
  246.  
  247.  
  248. Button{
  249. text: "stop"
  250. onClicked: {
  251. camera.stop();
  252. }
  253. }
  254.  
  255. Button{
  256. id:btnStart
  257. text: "start"
  258. onClicked: {
  259. camera.start();
  260. }
  261. }
  262.  
  263. }
  264.  
  265. }
  266. }
To copy to clipboard, switch view to plain text mode