Results 1 to 2 of 2

Thread: Writing to StatusBar

  1. #1
    Join Date
    Oct 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Writing to StatusBar

    I am trying to write a line of text to the statusBar if the function results a failure. Any help that can be provide is always welcome thank you

    Qt Code:
    1. void isOpen()
    2. {
    3. int result;
    4.  
    5. result = mbusProtocol.isOpen();
    6. if (result != FTALK_SUCCESS)
    7. {
    8.  
    9. exit(EXIT_FAILURE);
    10. }
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    I know how to do it with QActions, but my my minds running a blank on how to do it in the above isOpen function

    Qt Code:
    1. timer6Act = new QAction(QIcon("timer.png"), tr("&Timer 6"), this);
    2. timer6Act->setStatusTip(tr("Getting Data from Button6"));
    3. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer6()));
    To copy to clipboard, switch view to plain text mode 

    Main code below

    Qt Code:
    1. // Platform header
    2. #include <stdio.h>
    3. #include <stdlib.h>
    4. #include "seniorgui.h"
    5. #include "iconArea.h"
    6. // Include FieldTalk package header
    7. #include "MbusTcpMasterProtocol.hpp"
    8.  
    9. #include <QtGui>
    10. #include <QDesktopServices>
    11. #include <iostream>
    12. #include <fstream>
    13.  
    14. //#include <tchar.h>
    15.  
    16. #include <QUrl>
    17. using namespace std;
    18.  
    19.  
    20.  
    21. /*****************************************************************************
    22. * Gobal data
    23. *****************************************************************************/
    24. TCHAR *hostName = L"192.168.0.100";
    25. MbusTcpMasterProtocol mbusProtocol;
    26.  
    27. short readRegSet[20];
    28. short writeRegSet[20];
    29. int readBitSet[10];
    30. int writeBitSet[10];
    31.  
    32. long readLongSet[10];
    33. long writeLongSet[10];
    34.  
    35.  
    36. seniorGui::seniorGui(QWidget *parent, Qt::WFlags flags)
    37. : QMainWindow(parent, flags)
    38. {
    39.  
    40. previewArea = new iconArea();
    41. centralWidget = new QWidget;
    42. setCentralWidget(centralWidget);
    43.  
    44. QTimer *countdown = new QTimer;
    45.  
    46. QGridLayout *mainLayout = new QGridLayout;
    47. mainLayout->addWidget(previewArea, 0, 0, 0, 0);
    48. centralWidget->setLayout(mainLayout);
    49.  
    50. createActions();
    51. createMenus();
    52. createToolBars();
    53. createStatusBar();
    54.  
    55. setWindowTitle(tr("ModBus TCP/IP Senior Gui"));
    56. resize(minimumSizeHint());
    57.  
    58. }
    59.  
    60. void seniorGui::closeEvent(QCloseEvent *event)
    61. {
    62.  
    63. }
    64.  
    65. void seniorGui::about()
    66. {
    67. QMessageBox::about(this, tr("About Application"),
    68. tr("This is a <b>Application</b> that will use"
    69. "ModBus TCP/IP to connect and control several devices"));
    70. }
    71.  
    72. void seniorGui::createActions()
    73. {
    74. connectAct = new QAction(QIcon("connect.png"), tr("&Connect"), this);
    75. connectAct->setStatusTip(tr("Connect to IP Address"));
    76. connect(connectAct, SIGNAL(clicked()), this, SLOT(mbusProtocol.openProtocol(hostName)));
    77.  
    78. helpAct = new QAction(QIcon("help.gif"), tr("&help"), this);
    79. helpAct->setStatusTip(tr("Let's Help you out"));
    80. //connect(helpAct, SIGNAL(clicked()), this, SLOT(helpFile()));
    81.  
    82. qtAct = new QAction(QIcon("qt.png"), tr("&Qt"), this);
    83. qtAct->setStatusTip(tr("Learn more about Qt"));
    84. connect(qtAct, SIGNAL(clicked()), this, SLOT(qtHelp()));
    85.  
    86. disconnectAct = new QAction(QIcon("Disconnect.png"), tr("&Disconnect"), this);
    87. disconnectAct->setStatusTip(tr("Disconnecting from Module"));
    88. connect(disconnectAct, SIGNAL(clicked()), this, SLOT(mbusProtocol.closeProtocol()));
    89.  
    90. checkAct = new QAction(QIcon("check.png"), tr("&Check"), this);
    91. disconnectAct->setStatusTip(tr("Disconnecting from Module"));
    92. connect(checkAct, SIGNAL(clicked()), this, SLOT(isOpen()));
    93.  
    94. timer1Act = new QAction(QIcon("timer.png"), tr("&Timer 1"), this);
    95. timer1Act->setStatusTip(tr("Getting Data from Button1"));
    96. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer1()));
    97.  
    98. timer2Act = new QAction(QIcon("timer.png"), tr("&Timer 2"), this);
    99. timer2Act->setStatusTip(tr("Getting Data from Button3"));
    100. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer2()));
    101.  
    102. timer3Act = new QAction(QIcon("timer.png"), tr("&Timer 3"), this);
    103. timer3Act->setStatusTip(tr("Getting Data from Button3"));
    104. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer3()));
    105.  
    106. timer4Act = new QAction(QIcon("timer.png"), tr("&Timer 4"), this);
    107. timer4Act->setStatusTip(tr("Getting Data from Button4"));
    108. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer4()));
    109.  
    110. timer5Act = new QAction(QIcon("timer.png"), tr("&Timer 5"), this);
    111. timer5Act->setStatusTip(tr("Getting Data from Button5"));
    112. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer5()));
    113.  
    114. timer6Act = new QAction(QIcon("timer.png"), tr("&Timer 6"), this);
    115. timer6Act->setStatusTip(tr("Getting Data from Button6"));
    116. connect(checkAct, SIGNAL(clicked()), this, SLOT(timer6()));
    117.  
    118. }
    119.  
    120. void seniorGui::createToolBars()
    121. {
    122. fileToolBar = addToolBar(tr("Connect"));
    123. fileToolBar->addAction(connectAct);
    124. fileToolBar->addAction(disconnectAct);
    125. fileToolBar->addAction(checkAct);
    126.  
    127.  
    128. fileToolBar = addToolBar(tr("Help"));
    129. fileToolBar->addAction(helpAct);
    130. fileToolBar->addAction(qtAct);
    131.  
    132.  
    133. }
    134. void seniorGui::createMenus()
    135. {
    136. fileMenu = menuBar()->addMenu(tr("&File"));
    137. fileMenu->addAction(connectAct);
    138. fileMenu->addAction(disconnectAct);
    139. fileMenu->addAction(checkAct);
    140.  
    141.  
    142. fileMenu = menuBar()->addMenu(tr("Read Data"));
    143. fileMenu->addAction(timer1Act);
    144. fileMenu->addAction(timer2Act);
    145. fileMenu->addAction(timer3Act);
    146. fileMenu->addAction(timer4Act);
    147. fileMenu->addAction(timer5Act);
    148. fileMenu->addAction(timer6Act);
    149.  
    150.  
    151. fileMenu = menuBar()->addMenu(tr("&Help"));
    152. fileMenu->addAction(helpAct);
    153. fileMenu->addAction(qtAct);
    154. }
    155.  
    156.  
    157. void isOpen()
    158. {
    159. int result;
    160.  
    161. result = mbusProtocol.isOpen();
    162. if (result != FTALK_SUCCESS)
    163. {
    164.  
    165. exit(EXIT_FAILURE);
    166. }
    167.  
    168. }
    169.  
    170.  
    171.  
    172. void seniorGui::timer1()
    173. {
    174. count = 60000;
    175. while (count > 0)
    176. {
    177. mbusProtocol.readCoils(1,10,readBitSet,sizeof(readBitSet) / sizeof(int));
    178. // read data from device
    179. count--;
    180. }
    181. if(count <=0)
    182. {
    183. ofstream *dataFile = new ofstream;
    184. dataFile->open("data.txt");
    185. dataFile->close();
    186. //export data to text file
    187. }
    188. }
    189. void seniorGui::timer2()
    190. {
    191. count = 60000;
    192. while (count > 0)
    193. {
    194. mbusProtocol.readCoils(1,10,readBitSet,sizeof(readBitSet) / sizeof(int));
    195. // read data from device
    196. count--;
    197. }
    198. if(count <=0)
    199. {
    200. ofstream *dataFile = new ofstream;
    201. dataFile->open("data.txt");
    202. dataFile->close();
    203. //export data to text file
    204. }
    205. }
    206. void seniorGui::timer3()
    207. {
    208. count = 60000;
    209. while (count > 0)
    210. {
    211. mbusProtocol.readCoils(1,10,readBitSet,sizeof(readBitSet) / sizeof(int));
    212. // read data from device
    213. count--;
    214. }
    215. if(count <=0)
    216. {
    217. ofstream *dataFile = new ofstream;
    218. dataFile->open("data.txt");
    219. dataFile->close();
    220. //export data to text file
    221. }
    222. }
    223. void seniorGui::timer4()
    224. {
    225. count = 60000;
    226. while (count > 0)
    227. {
    228. mbusProtocol.readCoils(1,10,readBitSet,sizeof(readBitSet) / sizeof(int));
    229. // read data from device
    230. count--;
    231. }
    232. if(count <=0)
    233. {
    234. ofstream *dataFile = new ofstream;
    235. dataFile->open("data.txt");
    236. dataFile->close();
    237. //export data to text file
    238. }
    239. }
    240. void seniorGui::timer5()
    241. {
    242. count = 60000;
    243. while (count > 0)
    244. {
    245. mbusProtocol.readCoils(1,10,readBitSet,sizeof(readBitSet) / sizeof(int));
    246. // read data from device
    247. count--;
    248. }
    249. if(count <=0)
    250. {
    251. ofstream *dataFile = new ofstream;
    252. dataFile->open("data.txt");
    253. dataFile->close();
    254. //export data to text file
    255. }
    256. }
    257. void seniorGui::timer6()
    258. {
    259. count = 60000;
    260. while (count > 0)
    261. {
    262. mbusProtocol.readCoils(1,10,readBitSet,sizeof(readBitSet) / sizeof(int));
    263. // read data from device
    264. count--;
    265. }
    266. if(count <=0)
    267. {
    268. ofstream *dataFile = new ofstream;
    269. dataFile->open("data.txt");
    270. dataFile->close();
    271. //export data to text file
    272. }
    273. }
    274. void seniorGui::createStatusBar()
    275. {
    276. statusBar()->showMessage(tr("Ready"));
    277. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Writing to StatusBar

    Qt Code:
    1. void isOpen()
    2. {
    3. int result;
    4.  
    5. result = mbusProtocol.isOpen();
    6. if(result != FTALK_SUCCESS)
    7. {
    8. mainWindow->statusBar()->showMessage("Failure - mbusProtocol is not open"); //<<<<<<<<<<<<<<<<
    9. exit(EXIT_FAILURE);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. QDialog StatusBar
    By skuda in forum Qt Programming
    Replies: 5
    Last Post: 16th July 2010, 02:07
  2. statusbar
    By bhogasena in forum Qt Programming
    Replies: 7
    Last Post: 3rd February 2009, 15:54
  3. Designer and statusbar
    By zolookas in forum Qt Tools
    Replies: 3
    Last Post: 27th June 2008, 14:56
  4. forecolor of statusbar
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 08:55
  5. problem with statusbar
    By philipp1 in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2006, 08:12

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.