Hello Everyone,
I tried adding two timers to my window one for showing the time that some method is being run, the other displaying some information regarding the same method.
to be more precise, the first timer specifies the elapsed time in the realtime , in the form of "00:00:00:00" (as for day:hour:min:sec) that shows how long a method has been being running.
the other timer, gets the progress information of the such method, meaning how many steps have been passed and how many remains, this kind of stuff .
the first timer interval is set to emit every 1000ms , and the second timer is set to 10 ms.
this is how the code looks like now :
void frmCustomNetwork::Init()
{
InitFunctions();
//set timer
connect(timer,SIGNAL(timeout()),this,SLOT(on_TimerTick()));
timer->setInterval(1000);
connect(timerfast,SIGNAL(timeout()),this,SLOT(on_TimerFastTick()));
timerfast->setInterval(10);
//create a new network object
net = new Network(Layers,Network::TrainMode::Sequential,0);
ui->customPlot->addGraph();
// give the axes some labels:
ui->customPlot->xAxis->setLabel("epochs");
ui->customPlot->yAxis->setLabel("errors");
// set axes ranges, so we see all data:
ui->customPlot->xAxis->setRange(ui->txtXaxisLower->text().toFloat(), ui->txtXaxisUpper->text().toFloat());
ui->customPlot->yAxis->setRange(ui->txtYaxisLower->text().toFloat(), ui->txtYaxisUpper->text().toFloat());
ui->sliderEpoch->setMaximum(ui->txtXaxisUpper->text().toInt());
}
...
void frmCustomNetwork::on_btnTrain_clicked()
{
try
{
if( P.size() == 0 || T.size() == 0)
{
QMessageBox::warning(this,
"No Sample for training is set",
"You need to specify some samples with their respective desired outputs first");
return;
}
elapsedSeconds=0;
timer->start();
timerfast->start();
connect(&watcher,SIGNAL(finished()),this,SLOT(on_ThreadJobFinshed()));
future = QtConcurrent::run(this,&frmCustomNetwork::Rec,ui->chkPlot->isChecked());
watcher.setFuture(future);
}
catch(QException ex)
{
QMessageBox::critical(this,
"Exception occured in on_btnTrain_clicked()",ex.
what());
}
catch(std::exception ex)
{
QMessageBox::critical(this,
"Exception occured in on_btnTrain_clicked()",ex.
what());
}
catch(...)
{
QMessageBox::critical(this,
"Exception occured on_btnTrain_clicked()",
"Uknown Exception occured");
}
}
void frmCustomNetwork::Init()
{
InitFunctions();
//set timer
timer = new QTimer(0);
connect(timer,SIGNAL(timeout()),this,SLOT(on_TimerTick()));
timer->setInterval(1000);
timerfast = new QTimer(this);
connect(timerfast,SIGNAL(timeout()),this,SLOT(on_TimerFastTick()));
timerfast->setInterval(10);
//create a new network object
net = new Network(Layers,Network::TrainMode::Sequential,0);
ui->customPlot->addGraph();
// give the axes some labels:
ui->customPlot->xAxis->setLabel("epochs");
ui->customPlot->yAxis->setLabel("errors");
// set axes ranges, so we see all data:
ui->customPlot->xAxis->setRange(ui->txtXaxisLower->text().toFloat(), ui->txtXaxisUpper->text().toFloat());
ui->customPlot->yAxis->setRange(ui->txtYaxisLower->text().toFloat(), ui->txtYaxisUpper->text().toFloat());
ui->sliderEpoch->setMaximum(ui->txtXaxisUpper->text().toInt());
}
...
void frmCustomNetwork::on_btnTrain_clicked()
{
try
{
if( P.size() == 0 || T.size() == 0)
{
QMessageBox::warning(this,"No Sample for training is set","You need to specify some samples with their respective desired outputs first");
return;
}
elapsedSeconds=0;
timer->start();
timerfast->start();
connect(&watcher,SIGNAL(finished()),this,SLOT(on_ThreadJobFinshed()));
future = QtConcurrent::run(this,&frmCustomNetwork::Rec,ui->chkPlot->isChecked());
watcher.setFuture(future);
}
catch(QException ex)
{
QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()",ex.what());
}
catch(std::exception ex)
{
QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()",ex.what());
}
catch(...)
{
QMessageBox::critical(this,"Exception occured on_btnTrain_clicked()","Uknown Exception occured");
}
}
To copy to clipboard, switch view to plain text mode
and these are the timers and watchers slot respectively.
void frmCustomNetwork::on_TimerTick()
{
try
{
elapsedSeconds++;
day = elapsedSeconds / (24*3600);
hour = (elapsedSeconds % (24*3600)) / 3600 ;
min = ((elapsedSeconds % (24*3600)) % 3600) / 60;
second = ((elapsedSeconds % (24*3600)) % 3600) % 60;
}
catch(QException ex)
{
QMessageBox::critical(this,
"Exception occured in on_btnTrain_clicked()",ex.
what());
}
catch(...)
{
QMessageBox::critical(this,
"Exception occured in on_btnTrain_clicked()",
"UnExpected Exception occured! ");
}
}
void frmCustomNetwork::on_TimerFastTick()
{
QString patternIndex
= QString::number(net
->GetCurrentPatternNumber
());
ui->lblCurrentEpoch->setText(epoch);
ui->lblCurrentPattern->setText(patternIndex);
}
void frmCustomNetwork::on_ThreadJobFinshed()
{
timer->stop();
timerfast->stop();
elapsedSeconds = 0;
}
void frmCustomNetwork::on_TimerTick()
{
try
{
elapsedSeconds++;
day = elapsedSeconds / (24*3600);
hour = (elapsedSeconds % (24*3600)) / 3600 ;
min = ((elapsedSeconds % (24*3600)) % 3600) / 60;
second = ((elapsedSeconds % (24*3600)) % 3600) % 60;
ui->lblElapsedTime->setText(QString::number(day)+" : "+QString::number(hour)+" : "+QString::number(min)+" : "+QString::number(second));
}
catch(QException ex)
{
QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()",ex.what());
}
catch(...)
{
QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()","UnExpected Exception occured! ");
}
}
void frmCustomNetwork::on_TimerFastTick()
{
QString epoch = QString::number(net->GetCurrentEpochNumber());
QString patternIndex = QString::number(net->GetCurrentPatternNumber());
ui->lblCurrentEpoch->setText(epoch);
ui->lblCurrentPattern->setText(patternIndex);
}
void frmCustomNetwork::on_ThreadJobFinshed()
{
timer->stop();
timerfast->stop();
elapsedSeconds = 0;
}
To copy to clipboard, switch view to plain text mode
Now when the application runs, everything is just fine, when the method in question ends, the application crashes , and inside QtCreator I can see these error messages:
Starting G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe...
QPainter::begin: Paint device returned engine
== 0, type
: 3 QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted
The program has unexpectedly finished.
G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe crashed
Starting G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe...
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted
The program has unexpectedly finished.
G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe crashed
To copy to clipboard, switch view to plain text mode
Update
For some time it seems to be running just fine, but again it fails unexpectedly : here is another error message that poped up just after executing the method in question successfully for 3 times, (on the forth time this is what I get):
QMetaObject::connectSlotsByName: No matching
signal for on_btnLoadCorrectSamples_clicked
() QMetaObject::connectSlotsByName: No matching
signal for on_btnLoadWrongSamples_clicked
() QPainter::begin: Paint device returned engine
== 0, type
: 3 QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted
The program has unexpectedly finished.
G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe crashed
QMetaObject::connectSlotsByName: No matching signal for on_btnLoadCorrectSamples_clicked()
QMetaObject::connectSlotsByName: No matching signal for on_btnLoadWrongSamples_clicked()
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted
The program has unexpectedly finished.
G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe crashed
To copy to clipboard, switch view to plain text mode
Whats causing it ?
I also tried putting
QCoreApplication::processEvents();
To copy to clipboard, switch view to plain text mode
in timer slots, but that doesnt prevent crashes.
Bookmarks