[SOLVED] SIGSEGV 11 - on close from the taskbar but not from the mainwindow (x) cloase button
-
Hi,
From a quick look it seems fine, what does AtpSingleApplication look like ?
On a side note, you should use qobject_cast rather than dynamic_cast since you are casting from a QObject
-
- AtpSingleApplication
@AtpSingleApplication* AtpSingleApplication::instance = NULL;
void AtpSingleApplication::sysInit(const QString &appId) {
qDebug()<<"AtpSingleApplication sysInit";
mutexEventsLocker = NULL;
instance = this;
actWin = 0;
peer = new AtpLocalPeer(this, appId);
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
}AtpSingleApplication::AtpSingleApplication(int &argc, char **argv) : QApplication(argc, argv) {
qDebug()<<"Start AtpSingleApplication";
sysInit("atp");
}AtpSingleApplication::~AtpSingleApplication(){
qDebug()<<"Exit AtpSingleApplication";
}AtpSingleApplication* AtpSingleApplication::getInstance() {
qDebug()<<"AtpSingleApplication getInstance";
return instance;
}bool AtpSingleApplication::isRunning() {
qDebug()<<"AtpSingleApplication isRunning";
return peer->isClient();
}bool AtpSingleApplication::sendMessage(const QString &message, int timeout) {
qDebug()<<"AtpSingleApplication sendMessage";
return peer->sendMessage(message, timeout);
}QString AtpSingleApplication::id() const {
qDebug()<<"AtpSingleApplication id";
return peer->applicationId();
}void AtpSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) {
qDebug()<<"AtpSingleApplication setActiveWindow";
actWin = aw;
if (activateOnMessage)
connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
else
disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
}QWidget* AtpSingleApplication::activationWindow() const {
qDebug()<<"AtpSingleApplication activationWindow";
return actWin;
}void AtpSingleApplication::activateWindow() {
qDebug()<<"AtpSingleApplication activateWindow";
if (actWin) {
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
actWin->raise();
actWin->activateWindow();
}
}bool AtpSingleApplication::event(QEvent* e) {
qDebug()<<"AtpSingleApplication event";
QFileOpenEvent* foe = dynamic_cast<QFileOpenEvent*>(e);
if (foe!=NULL) {
emit(fileOpenRequestReceived(foe->file()));
e->accept();
qDebug() << "AtpSingleApplication::event: type: " << e->type() << ": OK";
return true;
}bool ret = QApplication::event(e);
return ret;
}@ - AtpSingleApplication
-
output from close on taskbar
@[../../../electricity/src/main/main.cpp:15, void catchSigPipe(int)]
Debug: SIGPIPE caught: 11
[../../../electricity/src/main/main.cpp:15, void catchSigPipe(int)]
Debug: SIGPIPE caught: 11
[../../../electricity/src/main/main.cpp:15, void catchSigPipe(int)]
Debug: SIGPIPE caught: 11
[../../../electricity/src/main/main.cpp:15, void catchSigPipe(int)]
Debug: SIGPIPE caught: 11
[../../../electricity/src/main/main.cpp:15, void catchSigPipe(int)]
Debug: SIGPIPE caught: 11
/home/andrei/Qt-projects/electricity/debug/electricity-bin exited with code 0@output from close (x) button
@ Debug: "/home/andrei/Qt-projects/electricity/debug/atp.ini"
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:66, void AtpMainWindow::writeSettings()]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp/atpElectricity.ini"
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:25, virtual AtpMainWindow::~AtpMainWindow()]
Debug: Exit AtpMainWindow
/home/andrei/Qt-projects/electricity/debug/electricity-bin exited with code 0@why this difference?
-
Did you try to run it in a debugger ?
You might be using something that has been already destroyed.
Also you have a memory leak in your main. you never delete your app.
On a side note Qt already proposes QtSingleApplication in its "Solution" catalog.
-
bq. On a side note Qt already proposes QtSingleApplication in its “Solution” catalog.
yes is true I've found it "here":http://doc.qt.digia.com/solutions/4/qtsingleapplication/qtsingleapplication.html
but not in Qt 5.3 so I can not do like #include <QSingleApplication> and because of that I will use mine one.. witch is not perfect but tried to copy some info from there... -
The solutions are not part of either Qt 4 or 5 you have to download them and integrate them in your project
-
ahammm.. thanks.. I'll try this... never knew about this any way about memory leak as far as i remember I've read somewere that Qt will manage this and close everithing for me... can you bring a good example of how I should close it not to have that memory leak? it is possible to receive because of that SIGSEGV?
-
Qt does indeed help with memory management through e.g QObject parent/child handling but it doesn't replace everything.
@
int main(int argc, char *argv[]){
//snip
AtpSingleApplication *app = new AtpSingleApplication(appId, argc, argv); << allocating the application on the heap
app->setOrganizationName("atp");
app->setOrganizationDomain("atp-trading.com");
app->setApplicationName("@atp@");
app->setApplicationVersion("1");
app->setApplicationDisplayName("atp");
//snip again
AtpMainWindow win;
win.show();
return app->exec(); << you don't delete the application, Qt can't do it for you.
}
@ -
by the way I've run the program in windows and bealiveme no SIGSEGV. usualy in windows there is a message box but everithing was fine.. wat is mre anoing is why is troing out SIGSEGV if the return is 0 - app finish corectly hm... have to do more reasearch - only on linux enviroment
-
Memory management is not the same in both OS. Did you run it using a debugger ? What happens if you delete the app object by hand ?
-
- main.cpp
@//main run
int ret = app->exec();
qDebug()<< "Del app"; //just to monitor the behaviour
delete app;
qDebug()<< "Del app after"; //just to monitor the behaviour
return ret;
@
this is perfect under linux exit with 0 end no signal caught;
- main.cpp
-
Are you can just create app on the stack
-
sorry but i do not understand what do you want to say.
bq. Are you can just create app on the stack
what that means?? Sorry but englisn is not my native language -
Search for "stack vs heap"