Hello,
My application is composed of an "Icone" (Personal class that setup a QSystemTrayIcon with a QMenu).
This Icone creates a "Veilleur" object (Personal class that simulate a service in order to administrate a client side connection to a server).
So the "Veilleur" creates a "MailChecker" (Personal class that checks for new mails on a server).
At the end, the "MailChecker" use a QTcpSocket to connect to the server.
The problem is that today I need to developp the "Veilleur" class, and a strange thing as appeared : I can't add anything !
For example, if I want to add a QAction (private or public) the application will fall down.
The application as no problem to pass the builder : no errors, no warning... Nothing.
But when I launch it, I get a Windows error box saying me that the application as encoutered an error and must be closed...
I can't understand the problem, so I put here my code... As reduced as possible .
main.cpp
#include <QApplication>
#include <QtGui>
#include "Icone.h"
int main(int argc, char *argv[])
{
Icone mon_icone;
return app.exec();
}
#include <QApplication>
#include <QtGui>
#include "Icone.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Icone mon_icone;
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Icone.h
#ifndef ICONE_H
#define ICONE_H
#include "Veilleur.h"
#include <iostream>
#include <QSystemTrayIcon>
#include <QWidget>
{
Q_OBJECT
public:
Icone();
protected:
[...]
private slots:
[...]
private:
// QActions and QMenus
// [...]
Veilleur mon_veilleur;
};
#endif
#ifndef ICONE_H
#define ICONE_H
#include "Veilleur.h"
#include <iostream>
#include <QSystemTrayIcon>
#include <QWidget>
class QAction;
class QMenu;
class Icone : public QWidget
{
Q_OBJECT
public:
Icone();
protected:
[...]
private slots:
[...]
private:
// QActions and QMenus
// [...]
QSystemTrayIcon *trayIcon;
Veilleur mon_veilleur;
};
#endif
To copy to clipboard, switch view to plain text mode
Icone.cpp
#include <QtGui>
#include "Icone.h"
Icone::Icone()
{
Creer_actions(); // Initialise the QActions
Creer_menu(); // Initialise the QMenus
Creer_TrayIcon(); // Initialise the trayicon and bind it the QMenus
}
#include <QtGui>
#include "Icone.h"
Icone::Icone()
{
Creer_actions(); // Initialise the QActions
Creer_menu(); // Initialise the QMenus
Creer_TrayIcon(); // Initialise the trayicon and bind it the QMenus
}
To copy to clipboard, switch view to plain text mode
Veilleur.h
#ifndef Veilleur_h
#define Veilleur_h
#include "MailChecker.h"
#include <QTextStream>
#include <QObject>
#include <QTimer>
// Added in order to try to add a QAction
#include <iostream>
#include <QWidget>
{
Q_OBJECT
public:
Veilleur();
[...]
private slots:
[...]
private:
MailChecker mChecker;
//MailChecker mCheckersecond; // Crash the application if uncommented
//QAction *Act_Tic; // Crash the application if uncommented
//QAction *Act_Ticlol; // Crash the application if uncommented
};
#endif
#ifndef Veilleur_h
#define Veilleur_h
#include "MailChecker.h"
#include <QTextStream>
#include <QObject>
#include <QTimer>
// Added in order to try to add a QAction
#include <iostream>
#include <QWidget>
class QAction;
class QMenu;
class Veilleur : public QObject
{
Q_OBJECT
public:
Veilleur();
[...]
private slots:
[...]
private:
MailChecker mChecker;
//MailChecker mCheckersecond; // Crash the application if uncommented
//QAction *Act_Tic; // Crash the application if uncommented
//QAction *Act_Ticlol; // Crash the application if uncommented
};
#endif
To copy to clipboard, switch view to plain text mode
Veilleur.cpp
#include <iostream>
#include <QApplication>
#include "Veilleur.h"
{
}
#include <iostream>
#include <QApplication>
#include "Veilleur.h"
Veilleur::Veilleur() : QObject()
{
}
To copy to clipboard, switch view to plain text mode
MailChecker.h
#ifndef MailChecker_h
#define MailChecker_h
#include <QThread>
#include <QTextStream>
#include <QSettings>
#include <QObject>
#include <QTcpSocket>
{
Q_OBJECT
public:
MailChecker();
[...]
private slots:
private:
[...]
};
#endif
#ifndef MailChecker_h
#define MailChecker_h
#include <QThread>
#include <QTextStream>
#include <QSettings>
#include <QObject>
#include <QTcpSocket>
class QTcpSocket;
class MailChecker : public QObject
{
Q_OBJECT
public:
MailChecker();
[...]
private slots:
void afficher_erreur_socket(QAbstractSocket::SocketError socketError);
private:
[...]
QTcpSocket *socket_r;
};
#endif
To copy to clipboard, switch view to plain text mode
MailChecker.cpp
#include <iostream>
#include <QApplication>
#include <QHostAddress>
#include <QTcpSocket>
#include <QStringList>
#include "MailChecker.h"
MailChecker
::MailChecker() : QObject(){
}
void MailChecker
::afficher_erreur_socket(QAbstractSocket::SocketError socketError
) {
switch (socketError)
{
break;
std::cout << "\n ERREUR SOCKET : Host not found" << std::endl;
break;
std::cout << "\n ERREUR SOCKET : Connection refused by peer" << std::endl;
break;
default:
std::cout << "\n ERREUR SOCKET : \n" << socket_r->errorString().toStdString() << std::endl;
}
}
#include <iostream>
#include <QApplication>
#include <QHostAddress>
#include <QTcpSocket>
#include <QStringList>
#include "MailChecker.h"
MailChecker::MailChecker() : QObject()
{
connect(socket_r, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(afficher_erreur_socket(QAbstractSocket::SocketError)));
}
void MailChecker::afficher_erreur_socket(QAbstractSocket::SocketError socketError)
{
switch (socketError)
{
case QAbstractSocket::RemoteHostClosedError:
break;
case QAbstractSocket::HostNotFoundError:
std::cout << "\n ERREUR SOCKET : Host not found" << std::endl;
break;
case QAbstractSocket::ConnectionRefusedError:
std::cout << "\n ERREUR SOCKET : Connection refused by peer" << std::endl;
break;
default:
std::cout << "\n ERREUR SOCKET : \n" << socket_r->errorString().toStdString() << std::endl;
}
}
To copy to clipboard, switch view to plain text mode
I'm sure I made my nOOb another time... But I'm a nOOb .
I can't understand what's the problem,
I can't understand why the application crashes if I add an object,
I can't understand why the application has been compile and built but crashes...
I think it's a class initialisation problem, but I can't see what.
Perhaps coul you help me ?
Thanks
Bookmarks