Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] SIGSEGV 11 - on close from the taskbar but not from the mainwindow (x) cloase button

[SOLVED] SIGSEGV 11 - on close from the taskbar but not from the mainwindow (x) cloase button

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arsinte_andrei
    wrote on last edited by
    #1

    I have a strange situation where I get a SIGSEGV with the int 11 on application close but only from the taskbar - Linux Kubuntu 14.04.
    How can I manage this?

    • main.cpp
      @#include <stdio.h>

    #include <QDebug>

    #if defined(Q_OS_LINUX)
    #include <signal.h>
    #endif

    #include "AtpSingleApplication.h"
    #include "AtpSettings.h"
    #include "AtpMainWindow.h"

    #if defined(Q_OS_LINUX)
    void catchSigPipe(int s){
    qDebug() << "SIGPIPE caught: " << s;
    }
    #endif

    void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
    QByteArray localMsg = message.toLocal8Bit();
    // QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit();

    switch (type) {
    case QtDebugMsg:
    fprintf(stderr,/* "%s - / "[%s:%u, %s]\n Debug: %s \n", /currentTime.constData(),/ context.file, context.line, context.function, localMsg.constData());
    fflush(stderr);
    break;
    case QtWarningMsg:
    fprintf(stderr, /
    "%s - / "[%s:%u, %s:]\n Warning: %s\n", /currentTime.constData(),/ context.file, context.line, context.function, localMsg.constData());
    fflush(stderr);
    break;
    case QtCriticalMsg:
    fprintf(stderr, /
    "%s - / "[%s:%u, %s]\n Critical: %s\n", /currentTime.constData(),/ context.file, context.line, context.function, localMsg.constData());
    fflush(stderr);
    break;
    case QtFatalMsg:
    fprintf(stderr, /
    "%s -*/ "[%s:%u, %s]\n Fatal: %s\n", /currentTime.constData(),/ context.file, context.line, context.function, localMsg.constData());
    fflush(stderr);
    abort();
    }
    }

    int main(int argc, char *argv[]){

    //debug
    qInstallMessageHandler(messageHandler);
    //AppId
    QString appId = "@atp@";
    for (int i=0; i<argc; i++) {
    QString a = argv[i];
    if (a=="-app-id" && i+1<argc) {
    appId = argv[i+1];
    }
    }
    //start app
    AtpSingleApplication *app = new AtpSingleApplication(appId, argc, argv);
    app->setOrganizationName("atp");
    app->setOrganizationDomain("atp-trading.com");
    app->setApplicationName("@atp@");
    app->setApplicationVersion("1");
    app->setApplicationDisplayName("atp");
    //sigPipe problems
    #if defined(Q_OS_LINUX)
    signal(SIGPIPE,catchSigPipe);
    signal(SIGSEGV,catchSigPipe);
    #endif

    //init settings
    AtpSettings *mainSettings = new AtpSettings;

    //detect multiple instance
    if (!mainSettings->getAppMultipleInstance()) {
    // send arguments to running instance for further processing:
    if (app->sendMessage(app->arguments().join("\n"), 30000)) {
    qWarning("Application already running. Aborting...");
    return 0;
    }
    }
    //main window
    AtpMainWindow win;
    win.show();
    //main run
    return app->exec();
    }
    @

    • AtpMainWindow
      @
      AtpMainWindow::AtpMainWindow(QWidget *parent, bool hasMdiArea) : QMainWindow(parent){
      qDebug()<<"Start AtpMainWindow" << hasMdiArea;
      settingsMainWindow = new AtpSettings();
      qDebug() << settingsMainWindow->fileName();
      setWindowTitle("@atp@");

    AtpSingleApplication singleApp = dynamic_cast<AtpSingleApplication> (qApp);
    if (singleApp!=NULL) {
    singleApp->setActivationWindow(this);
    }
    readSettings();
    }

    AtpMainWindow::~AtpMainWindow(){
    qDebug()<<"Exit AtpMainWindow";
    }

    void AtpMainWindow::quit() {
    emit closeRequested();
    QMainWindow::close();
    }

    //event on close mainWindow
    void AtpMainWindow::closeEvent(QCloseEvent *e) {
    qDebug()<<"Start closeEvent";
    if (maybeSave()) {
    writeSettings();
    e->accept();
    QApplication::quit();
    } else {
    e->ignore();
    }
    }

    //save any unsaved data
    bool AtpMainWindow::maybeSave(){
    return true;
    }

    //Restores the application window settings (size, position, ...).
    void AtpMainWindow::readSettings() {
    qDebug()<<"readSettings";
    qDebug() << settingsMainWindow->fileName();
    QPoint windowPos = settingsMainWindow->getAppPosition();
    QSize windowSize = settingsMainWindow->getAppSize();
    resize(windowSize);
    move(windowPos);
    }

    // Stores the application window settings (size, position, ...).
    void AtpMainWindow::writeSettings() {
    qDebug()<<"writeSettings";
    qDebug() << settingsMainWindow->fileName();
    settingsMainWindow->setAppPosition(pos());
    settingsMainWindow->setAppSize(size());
    qDebug() << settingsMainWindow->fileName();
    }
    @

    I've done a lot of research.. nothing yet.. and what is curios is that is only from the taskbar.. how Qt manage thouse different?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arsinte_andrei
        wrote on last edited by
        #3
        • 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;
        }@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          arsinte_andrei
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • A Offline
              A Offline
              arsinte_andrei
              wrote on last edited by
              #6

              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...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                The solutions are not part of either Qt 4 or 5 you have to download them and integrate them in your project

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  arsinte_andrei
                  wrote on last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    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.
                    }
                    @

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      arsinte_andrei
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        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 ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          arsinte_andrei
                          wrote on last edited by
                          #12
                          • 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;
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Are you can just create app on the stack

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              arsinte_andrei
                              wrote on last edited by
                              #14

                              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

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Search for "stack vs heap"

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved