PDA

View Full Version : Writing to StatusBar



snowsoman
23rd November 2011, 17:36
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



void isOpen()
{
int result;

result = mbusProtocol.isOpen();
if (result != FTALK_SUCCESS)
{

exit(EXIT_FAILURE);
}

}


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



timer6Act = new QAction(QIcon("timer.png"), tr("&Timer 6"), this);
timer6Act->setStatusTip(tr("Getting Data from Button6"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer6()));


Main code below



// Platform header
#include <stdio.h>
#include <stdlib.h>
#include "seniorgui.h"
#include "iconArea.h"
// Include FieldTalk package header
#include "MbusTcpMasterProtocol.hpp"

#include <QtGui>
#include <QDesktopServices>
#include <iostream>
#include <fstream>

//#include <tchar.h>

#include <QUrl>
using namespace std;



/************************************************** ***************************
* Gobal data
************************************************** ***************************/
TCHAR *hostName = L"192.168.0.100";
MbusTcpMasterProtocol mbusProtocol;

short readRegSet[20];
short writeRegSet[20];
int readBitSet[10];
int writeBitSet[10];

long readLongSet[10];
long writeLongSet[10];


seniorGui::seniorGui(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{

previewArea = new iconArea();
centralWidget = new QWidget;
setCentralWidget(centralWidget);

QTimer *countdown = new QTimer;

QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(previewArea, 0, 0, 0, 0);
centralWidget->setLayout(mainLayout);

createActions();
createMenus();
createToolBars();
createStatusBar();

setWindowTitle(tr("ModBus TCP/IP Senior Gui"));
resize(minimumSizeHint());

}

void seniorGui::closeEvent(QCloseEvent *event)
{

}

void seniorGui::about()
{
QMessageBox::about(this, tr("About Application"),
tr("This is a <b>Application</b> that will use"
"ModBus TCP/IP to connect and control several devices"));
}

void seniorGui::createActions()
{
connectAct = new QAction(QIcon("connect.png"), tr("&Connect"), this);
connectAct->setStatusTip(tr("Connect to IP Address"));
connect(connectAct, SIGNAL(clicked()), this, SLOT(mbusProtocol.openProtocol(hostName)));

helpAct = new QAction(QIcon("help.gif"), tr("&help"), this);
helpAct->setStatusTip(tr("Let's Help you out"));
//connect(helpAct, SIGNAL(clicked()), this, SLOT(helpFile()));

qtAct = new QAction(QIcon("qt.png"), tr("&Qt"), this);
qtAct->setStatusTip(tr("Learn more about Qt"));
connect(qtAct, SIGNAL(clicked()), this, SLOT(qtHelp()));

disconnectAct = new QAction(QIcon("Disconnect.png"), tr("&Disconnect"), this);
disconnectAct->setStatusTip(tr("Disconnecting from Module"));
connect(disconnectAct, SIGNAL(clicked()), this, SLOT(mbusProtocol.closeProtocol()));

checkAct = new QAction(QIcon("check.png"), tr("&Check"), this);
disconnectAct->setStatusTip(tr("Disconnecting from Module"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(isOpen()));

timer1Act = new QAction(QIcon("timer.png"), tr("&Timer 1"), this);
timer1Act->setStatusTip(tr("Getting Data from Button1"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer1()));

timer2Act = new QAction(QIcon("timer.png"), tr("&Timer 2"), this);
timer2Act->setStatusTip(tr("Getting Data from Button3"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer2()));

timer3Act = new QAction(QIcon("timer.png"), tr("&Timer 3"), this);
timer3Act->setStatusTip(tr("Getting Data from Button3"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer3()));

timer4Act = new QAction(QIcon("timer.png"), tr("&Timer 4"), this);
timer4Act->setStatusTip(tr("Getting Data from Button4"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer4()));

timer5Act = new QAction(QIcon("timer.png"), tr("&Timer 5"), this);
timer5Act->setStatusTip(tr("Getting Data from Button5"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer5()));

timer6Act = new QAction(QIcon("timer.png"), tr("&Timer 6"), this);
timer6Act->setStatusTip(tr("Getting Data from Button6"));
connect(checkAct, SIGNAL(clicked()), this, SLOT(timer6()));

}

void seniorGui::createToolBars()
{
fileToolBar = addToolBar(tr("Connect"));
fileToolBar->addAction(connectAct);
fileToolBar->addAction(disconnectAct);
fileToolBar->addAction(checkAct);


fileToolBar = addToolBar(tr("Help"));
fileToolBar->addAction(helpAct);
fileToolBar->addAction(qtAct);


}
void seniorGui::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(connectAct);
fileMenu->addAction(disconnectAct);
fileMenu->addAction(checkAct);


fileMenu = menuBar()->addMenu(tr("Read Data"));
fileMenu->addAction(timer1Act);
fileMenu->addAction(timer2Act);
fileMenu->addAction(timer3Act);
fileMenu->addAction(timer4Act);
fileMenu->addAction(timer5Act);
fileMenu->addAction(timer6Act);


fileMenu = menuBar()->addMenu(tr("&Help"));
fileMenu->addAction(helpAct);
fileMenu->addAction(qtAct);
}


void isOpen()
{
int result;

result = mbusProtocol.isOpen();
if (result != FTALK_SUCCESS)
{

exit(EXIT_FAILURE);
}

}



void seniorGui::timer1()
{
count = 60000;
while (count > 0)
{
mbusProtocol.readCoils(1,10,readBitSet,sizeof(read BitSet) / sizeof(int));
// read data from device
count--;
}
if(count <=0)
{
ofstream *dataFile = new ofstream;
dataFile->open("data.txt");
dataFile->close();
//export data to text file
}
}
void seniorGui::timer2()
{
count = 60000;
while (count > 0)
{
mbusProtocol.readCoils(1,10,readBitSet,sizeof(read BitSet) / sizeof(int));
// read data from device
count--;
}
if(count <=0)
{
ofstream *dataFile = new ofstream;
dataFile->open("data.txt");
dataFile->close();
//export data to text file
}
}
void seniorGui::timer3()
{
count = 60000;
while (count > 0)
{
mbusProtocol.readCoils(1,10,readBitSet,sizeof(read BitSet) / sizeof(int));
// read data from device
count--;
}
if(count <=0)
{
ofstream *dataFile = new ofstream;
dataFile->open("data.txt");
dataFile->close();
//export data to text file
}
}
void seniorGui::timer4()
{
count = 60000;
while (count > 0)
{
mbusProtocol.readCoils(1,10,readBitSet,sizeof(read BitSet) / sizeof(int));
// read data from device
count--;
}
if(count <=0)
{
ofstream *dataFile = new ofstream;
dataFile->open("data.txt");
dataFile->close();
//export data to text file
}
}
void seniorGui::timer5()
{
count = 60000;
while (count > 0)
{
mbusProtocol.readCoils(1,10,readBitSet,sizeof(read BitSet) / sizeof(int));
// read data from device
count--;
}
if(count <=0)
{
ofstream *dataFile = new ofstream;
dataFile->open("data.txt");
dataFile->close();
//export data to text file
}
}
void seniorGui::timer6()
{
count = 60000;
while (count > 0)
{
mbusProtocol.readCoils(1,10,readBitSet,sizeof(read BitSet) / sizeof(int));
// read data from device
count--;
}
if(count <=0)
{
ofstream *dataFile = new ofstream;
dataFile->open("data.txt");
dataFile->close();
//export data to text file
}
}
void seniorGui::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}

Santosh Reddy
23rd November 2011, 17:50
void isOpen()
{
int result;

result = mbusProtocol.isOpen();
if(result != FTALK_SUCCESS)
{
mainWindow->statusBar()->showMessage("Failure - mbusProtocol is not open"); //<<<<<<<<<<<<<<<<
exit(EXIT_FAILURE);
}
}