Hello,
I have a Qt project like this (with usual include files, most of the code has been stripped so that it is easy to understand):
============================================
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Formd w;
QFileDialog fd;
fd.setMode ( QFileDialog::ExistingFiles );
QString Folder, OutFile;
ifstream ifs;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT(quit()));
return a.exec();
}
============================================
============================================
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
//formd.cpp
void Formd::OnO1() {
}
void Formd::OnO2() {
}
void Formd::OnO3() {
}
void Formd::OnO4() {
}
void Formd::OnStart() {
/*
code to process large file
*/
switch (buttonGroupXage)
{
case 0: {
/*
code to process large file
*/
progressNow = ( xInfo.CurrentSeekPosition / ( xInfo.TotalSizeOfAllFiles / 100));
if (progressNow > progressOld) {
progressOld = progressNow;
progressBarCompletion->setProgress( progressOld );
UpdateWindow();
}
}
case 1: {
/*
code to process large file and update progress bar
*/
}
break;
case 2: {
/*
code to process large file and update progress bar
*/
}
break;
case 3: {
/*
code to process large file and update progress bar
*/
}
break;
}
void OnCancel()
{
close();
}
void Formd::UpdateWindow()
{
textLabelCompletion->repaint();
textLabelFolder->repaint();
lineEditFolder->repaint();
textLabelInFile->repaint();
comboBoxInFile->repaint();
buttonGroupExchange->repaint();
radioButtonO1->repaint();
radioButtonO2->repaint();
radioButtonO3->repaint();
radioButtonO4->repaint();
spinBoxYear->repaint();
textLabelYear->repaint();
lineEditMonth->repaint();
buttonGroupType->repaint();
radioButtonD->repaint();
radioButtonText->repaint();
pushButtonCancel->repaint();
pushButtonStart->repaint();
}
============================================
There is a widget created as Formd having combo boxes, radio buttons, push buttons, edit boxes, static boxes etc.
The project compiled properly and doing what it is supposed to large extent. On one of the push button, the the function OnStart() is attached (slot/ connection). This function is processing a large file, therefore, takes a while to execute. I have two problems with this:
1. While this function is running, I am unable to cancel this process by push button cancel, which is having the code to terminate the programme. No controls for that matter are responding to keyboard or mouse clicks.
2. When this widget is minimised or hidden by another window, the widget does not refresh/ repaint until whole of the file is processed. (
This so happens in many applications on Linux including openOffice etc.). UpdateWindow code was put in to let the window refresh/ repaint and respond to mouse clicks and key board but didnot do the required thing.
Please help.
Alex