21altf
27th October 2011, 05:48
I have a program that works fine without signals, but when I add them I start having trouble.
Basecally, I'm building a QSplashScreen for this program and since this is a short program it doesnt hold very long. So I Tryed to create an alternative class with a especific slot for terminating this program using QTimer::start(ms);
the problem is, I dont want my main widget to start b4 this QSpalshScreen is closed. So I added a Signal, thatway when I terminate the QSplashScreen I would emit a signal and my QMainWindow would attach it to SLOT(show()).
Whats happening is: When the QSplashScreen terminates the program crashes with this error 255.
my program is:
--QSS.h--
#ifndef QSS_H
#define QSS_H
#include <QSplashScreen>
#include <QTimer>
#include <QWidget>
#include <QObject>
#include <QtGui>
class QMainWindow;
class QSS: public QSplashScreen {
Q_OBJECT
public:
explicit QSS(QSplashScreen *parent = 0);
void criarTimer();
public slots:
void fechar();
signals:
void fechou();
};
#endif // QSS_H
--QSS.cpp--
#include <QSS.h>
#include <QWidget>
#include <QObject>
#include <QSplashScreen>
QSS::QSS(QSplashScreen *parent) :
QSplashScreen(parent)
{
}
//slots
void QSS::fechar()
{
this->~QSplashScreen();
emit fechou();
}
//funções públicas
void QSS::criarTimer()
{
QTimer *tempo = new QTimer;
tempo->setSingleShot(true);
QObject::connect(tempo,SIGNAL(timeout()),this,SLOT (fechar()));
tempo->start(3000);
}
---main.cpp---
#include <QtGui/QApplication>
#include <QSplashScreen>
#include <QSS.h>
#include "teste3mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSS *splash = new QSS;
splash->setPixmap(QPixmap(":/images/circulo.png"));
splash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(QObject::tr("Setting up..."),topRight,Qt::black);
teste3MainWindow w;
splash->criarTimer();
QObject::connect(splash,SIGNAL(fechou()),&w,SLOT(show()));
return a.exec();
}
Tnx
Basecally, I'm building a QSplashScreen for this program and since this is a short program it doesnt hold very long. So I Tryed to create an alternative class with a especific slot for terminating this program using QTimer::start(ms);
the problem is, I dont want my main widget to start b4 this QSpalshScreen is closed. So I added a Signal, thatway when I terminate the QSplashScreen I would emit a signal and my QMainWindow would attach it to SLOT(show()).
Whats happening is: When the QSplashScreen terminates the program crashes with this error 255.
my program is:
--QSS.h--
#ifndef QSS_H
#define QSS_H
#include <QSplashScreen>
#include <QTimer>
#include <QWidget>
#include <QObject>
#include <QtGui>
class QMainWindow;
class QSS: public QSplashScreen {
Q_OBJECT
public:
explicit QSS(QSplashScreen *parent = 0);
void criarTimer();
public slots:
void fechar();
signals:
void fechou();
};
#endif // QSS_H
--QSS.cpp--
#include <QSS.h>
#include <QWidget>
#include <QObject>
#include <QSplashScreen>
QSS::QSS(QSplashScreen *parent) :
QSplashScreen(parent)
{
}
//slots
void QSS::fechar()
{
this->~QSplashScreen();
emit fechou();
}
//funções públicas
void QSS::criarTimer()
{
QTimer *tempo = new QTimer;
tempo->setSingleShot(true);
QObject::connect(tempo,SIGNAL(timeout()),this,SLOT (fechar()));
tempo->start(3000);
}
---main.cpp---
#include <QtGui/QApplication>
#include <QSplashScreen>
#include <QSS.h>
#include "teste3mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSS *splash = new QSS;
splash->setPixmap(QPixmap(":/images/circulo.png"));
splash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(QObject::tr("Setting up..."),topRight,Qt::black);
teste3MainWindow w;
splash->criarTimer();
QObject::connect(splash,SIGNAL(fechou()),&w,SLOT(show()));
return a.exec();
}
Tnx