Ok I read the article. But still cannot crack it. Somehow I think my best course of action to achieve what I want (show a widget smoothly while mainWindow and its components are loaded) is to use the QTimer::singleShot.
I´ve changed my whole code but i cannot get the whole idea of the timer I guess
So far I have this:
#include <QtGui/QApplication>
#include <QObject>
#include <QDesktopWidget>
#include "loadthread.h"
int main(int argc, char *argv[])
{
LoadingWidget *loadwidg = new LoadingWidget ();
loadwidg->show ();
MainWindow mainWin;
LoadThread * load_thread = new LoadThread (&mainWin);
QObject::connect (load_thread,
SIGNAL(load_finished
()), loadwidg,
SLOT(load_finished
()));
QTimer::singleShot (0,load_thread,
SLOT(load
()));
mainWin.show ();
return a.exec ();
}
#include <QtGui/QApplication>
#include <QObject>
#include <QDesktopWidget>
#include "loadthread.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setStyle (new IconSize ());
LoadingWidget *loadwidg = new LoadingWidget ();
loadwidg->show ();
QApplication::setStyle (new IconSize ());
MainWindow mainWin;
LoadThread * load_thread = new LoadThread (&mainWin);
QObject::connect (load_thread, SIGNAL(load_finished()), loadwidg, SLOT(load_finished()));
QTimer::singleShot (0,load_thread, SLOT(load()));
mainWin.show ();
return a.exec ();
}
To copy to clipboard, switch view to plain text mode
And the load class does this
#include "loadthread.h"
LoadThread::LoadThread(MainWindow * mainWin)
{
this->mainWin = mainWin;
}
void LoadThread::load (){
mainWin->setWindowTitle("Los Taninos Vinoteca");
mainWin->setWindowFlags (Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint);
//centrar imagen
mainWin
->setGeometry
( QStyle::alignedRect(Qt
::LeftToRight, Qt
::AlignCenter,mainWin
->size
(),qApp
->desktop
()->availableGeometry
()));
//some not interesting code
if (handler >= 0 && aux ==0 && capacidad >0){
mainWin->setHandler (handler);
}else{
if (capacidad == 0){
QMessageBox::critical (0,
QString ("NO MORE REGISTERS TO STORE DATA"),
QString ("No quedan más registros para guardar información fiscal\n\nNo se podrá realizar ninguna operación\nrelacionada con el controlador."),
QMessageBox::Ok);
}else QMessageBox::information (0,
QString ("NO FISCAL PRINTER"),
QString ("No se ha encontrado el controlador fiscal\nconectado, no se podrá facturar"));
mainWin->setHandler (0);
}
emit load_finished ();
}
#include "loadthread.h"
LoadThread::LoadThread(MainWindow * mainWin)
{
this->mainWin = mainWin;
}
void LoadThread::load (){
mainWin->setWindowTitle("Los Taninos Vinoteca");
mainWin->setWindowFlags (Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint);
//centrar imagen
mainWin->setGeometry( QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter,mainWin->size(),qApp->desktop()->availableGeometry()));
//some not interesting code
if (handler >= 0 && aux ==0 && capacidad >0){
mainWin->setHandler (handler);
}else{
if (capacidad == 0){
QMessageBox::critical (0, QString ("NO MORE REGISTERS TO STORE DATA"), QString ("No quedan más registros para guardar información fiscal\n\nNo se podrá realizar ninguna operación\nrelacionada con el controlador."), QMessageBox::Ok);
}else QMessageBox::information (0, QString ("NO FISCAL PRINTER"),QString ("No se ha encontrado el controlador fiscal\nconectado, no se podrá facturar"));
mainWin->setHandler (0);
}
emit load_finished ();
}
To copy to clipboard, switch view to plain text mode
Doing this the loading widget still not running at 40ms
Bookmarks