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 -> Segmentation fault --- Error in Custom Framework (with GDB Screenshot and Results)
Forum Updated to NodeBB v4.3 + New Features

[Solved] SIGSEGV -> Segmentation fault --- Error in Custom Framework (with GDB Screenshot and Results)

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 3.9k 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.
  • K Offline
    K Offline
    KeppePT
    wrote on last edited by
    #1

    I need help with my Custom Framework, i have add a screenshot of the GDB Result and a part of the Source Code
    -> Segmentation fault

    !http://www.keppe.org/img/sigsegv.png(Screenshot)!

    KMsgFw11Q.cpp
    @#include "KMsgFw11Q.h"
    #include <QFile>
    #include <QSslError>
    #include <QSslSocket>
    #include <QStringList>
    #include <QSslCertificate>

    KMsgFw11Q::KMsgFw11Q(QObject *parent) :
    QObject(parent)
    {
    tcpSocket = new QSslSocket();
    QList<QSslCertificate> cert = QSslCertificate::fromPath(QLatin1String(":/messenger.pem"));
    if (cert.length() >= 1)
    {
    QSslError HostNameMismatch = QSslError(QSslError::HostNameMismatch, cert.at(0));
    QSslError SelfSignedCertificate = QSslError(QSslError::SelfSignedCertificate, cert.at(0));
    QSslError UnableToGetLocalIssuerCertificate = QSslError(QSslError::UnableToGetLocalIssuerCertificate, cert.at(0));
    QSslError CertificateUntrusted = QSslError(QSslError::CertificateUntrusted, cert.at(0));
    QSslError UnableToVerifyFirstCertificate = QSslError(QSslError::UnableToVerifyFirstCertificate, cert.at(0));
    QSslError CertificateExpired = QSslError(QSslError::CertificateExpired, cert.at(0));
    sslErrors.append(HostNameMismatch);
    sslErrors.append(SelfSignedCertificate);
    sslErrors.append(UnableToGetLocalIssuerCertificate);
    sslErrors.append(CertificateUntrusted);
    sslErrors.append(UnableToVerifyFirstCertificate);
    sslErrors.append(CertificateExpired);
    }
    loggedIn = false;
    }
    /// More is excluded@

    KMsgFw11Q.h
    @#ifndef KMSGFW11Q_H
    #define KMSGFW11Q_H
    #include <QString>
    #include <QSslError>
    #include <QSslSocket>
    #include "KMsgFw_shared.h"

    class KMSGFWSHARED_EXPORT KMsgFw11Q : public QObject
    {
    Q_OBJECT

    public:
    KMsgFw11Q(QObject *parent = 0);
    int loginUser(QString username, QString password);
    int logoutUser();
    bool isLoggedIn();
    bool requestGetUserContacts();
    bool requestGetUserContactsLength();
    bool requestGetUserContactsRequests();
    bool requestGetUserContactsWithStates();
    bool requestGetUserFriendRequests();
    bool requestGetUserFriendRequestsLength();
    bool actionAddUserContact(QString username);
    bool actionDelUserContact(QString username);
    bool actionRemoveUserContact(QString username);
    bool requestGetAnotherUserOnlineState(QString username);
    bool requestGetUserOnlineState();
    bool actionSetUserOnlineState(int state);
    bool requestGetAnotherUserMessageState(QString username);
    bool requestGetUserMessageState();
    bool actionSetUserMessageState(QString message);
    bool requestGetAnotherUserAvatar(QString username);
    bool requestGetUserAvatar();
    bool actionSetUserAvatar(QString base64, QString format);
    bool requestGetAnotherUserNick(QString username);
    bool requestGetUserNick();
    bool actionSetUserNick(QString nick);
    bool requestGetAnotherUserMail(QString username);
    bool requestGetUserMail();
    bool actionSetUserMail(QString mail, bool vfo);
    bool actionSetUserPassword(QString oldpassword, QString newpassword);
    bool actionSendPokeToUser(QString username);
    bool actionSendMessageToUser(QString username, QString message, int id=-1);
    QString getUserContacts();
    QString getUserContactsLength();
    QString getUserContactsRequests();
    QString getUserContactsWithStates();
    QString getUserFriendRequests();
    QString getUserFriendRequestsLength();
    int addUserContact(QString username);
    int delUserContact(QString username);
    int removeUserContact(QString username);
    int getAnotherUserOnlineState(QString username);
    int getUserOnlineState();
    int setUserOnlineState(int state);
    QString getAnotherUserMessageState(QString username);
    QString getUserMessageState();
    int setUserMessageState(QString message);
    QString getAnotherUserNick(QString username);
    QString getUserNick();
    int setUserNick(QString nick);
    QString getAnotherUserMail(QString username);
    QString getUserMail();
    int setUserMail(QString mail, bool vfo);
    int setUserPassword(QString oldpassword, QString newpassword);
    int sendPokeToUser(QString username);
    int sendMessageToUser(QString username, QString message);
    bool isObjectIncoming();
    QString readObject();

    signals:
    void objectIncomed(QString object);

    private:
    QString workWithObjectWithEmit(QByteArray readed);
    QString workWithObject(QByteArray readed);
    QList<QSslError> sslErrors;
    QSslSocket *tcpSocket;
    bool loggedIn;
    };

    #endif // KMSGFW11Q_H
    @

    If you have any idea, it's nice if you me help

    (If you are german please made a german part for me, i am not perfect in english)

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

      Hi and welcome to devnet,

      Please re-run your program in debug mode, you'll have more information about what triggers the crash. One thing that I see that might be doing this is that you don't verify that list of certificate is not empty.

      Hope it helps

      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
      • K Offline
        K Offline
        KeppePT
        wrote on last edited by
        #3

        Sorry, i have no idea what is really needed, my Windows Version works fine

        http://www.keppe.org/gdboutput.html <- the contains is to long for a Post

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

          You are still running your program in release mode, change that. Have a look at the computer icon just above the green arrow, click on it change release to debug. Then start again using the debugger

          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
          • K Offline
            K Offline
            KeppePT
            wrote on last edited by
            #5

            I have made a screenshot, it's more needed?

            !http://www.keppe.org/img/debugmode.png(Screenshot)!

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KeppePT
              wrote on last edited by
              #6

              i have made the Object KMsgFw11Q *fw;
              fw = new KMsgFw11Q(this);

              Now have that

              !http://www.keppe.org/img/debugmode2.png(Screenshot)!

              Windows Debugger say me: QWidget: Must construct a QApplication before a QPaintDevice...

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

                Can you show your main.cpp ?

                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
                • K Offline
                  K Offline
                  KeppePT
                  wrote on last edited by
                  #8

                  @#include <QApplication>
                  #ifdef WIN32
                  #include <QUrl>
                  #include <QTimer>
                  #include <QProcess>
                  #include <QNetworkReply>
                  #include <QNetworkAccessManager>
                  #endif
                  #include <QStyleFactory>
                  #include <QMessageBox>
                  #include <QSettings>
                  #include <QFileInfo>
                  #include <QWidget>
                  #include <QStyle>
                  #include <QDir>
                  #include "frmLogin.h"
                  #include "frmUpdate.h"
                  #include "UpdateThread.h"

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

                  #ifdef Q_WS_WIN64
                  a.setApplicationName("Keppe Messenger (64bit)");
                  #else
                  a.setApplicationName("Keppe Messenger");
                  #endif
                  a.setApplicationVersion("1.0.0-19");

                  bool noupdate = false;
                  bool regupdate = false;
                  bool minimized = false;
                  bool resetstyle = false;
                  
                  foreach (const QString& argument, a.arguments())
                  {
                      if (argument == "--noupdate" || argument.left(11) == "--noupdate=")
                      {
                          noupdate = true;
                      }
                      if (argument == "--regupdate" || argument.left(12) == "--regupdate=")
                      {
                          regupdate = true;
                      }
                      if (argument == "--minimized" || argument.left(12) == "--minimized=")
                      {
                          minimized = true;
                      }
                      if (argument == "--resetstyle" || argument.left(13) == "--resetstyle=")
                      {
                          resetstyle = true;
                      }
                  }
                  

                  #ifdef SHARED
                  QDir pluginsDir = QFileInfo(a.applicationFilePath()).absoluteDir();
                  QDir::setCurrent(pluginsDir.path());
                  pluginsDir.cd("plugins");
                  a.addLibraryPath(pluginsDir.path());
                  pluginsDir.cd("styles");
                  a.addLibraryPath(pluginsDir.path());

                  #ifdef WIN32
                  if (regupdate)
                  {
                  QString applicationID;
                  #ifdef QT5
                  applicationID = "{490D16AC-E002-40EA-A563-94B5AC5B5D21}";
                  #else
                  #ifdef WIN64
                  applicationID = "{6932EC7F-0EB0-4C59-A93C-4D266B8D26DC}";
                  #elif defined(MSVC)
                  applicationID = "";
                  #else
                  applicationID = "{EE2292A2-0CCC-492F-BB0E-F104F972DC1B}";
                  #endif
                  #endif
                  QSettings regNormal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"+applicationID+"_is1",QSettings::NativeFormat);
                  if (regNormal.contains("DisplayName"))
                  {
                  regNormal.setValue("DisplayName",a.applicationName() + " " + a.applicationVersion());
                  }
                  if (regNormal.contains("DisplayVersion"))
                  {
                  regNormal.setValue("DisplayVersion",a.applicationVersion());
                  }
                  QSettings reg6432Node("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"+applicationID+"_is1",QSettings::NativeFormat);
                  if (reg6432Node.contains("DisplayName"))
                  {
                  reg6432Node.setValue("DisplayName",a.applicationName() + " " + a.applicationVersion());
                  }
                  if (reg6432Node.contains("DisplayVersion"))
                  {
                  reg6432Node.setValue("DisplayVersion",a.applicationVersion());
                  }
                  }
                  #else
                  Q_UNUSED(noupdate);
                  Q_UNUSED(regupdate);
                  #endif

                  if (resetstyle)
                  {
                      QSettings settings("Keppe","Keppe Messenger");
                      settings.beginGroup("Style");
                      settings.setValue("Custom", false);
                      settings.setValue("showBug", true);
                      settings.endGroup();
                  }
                  
                  QString versionType;
                  

                  #ifdef QT5
                  versionType = "32qt5";
                  #else
                  #ifdef WIN64
                  versionType = "64qt4";
                  #elif defined(MSVC)
                  versionType = "vcqt4";
                  #else
                  versionType = "32qt4";
                  #endif
                  #endif

                  #ifdef WIN32

                  if (!noupdate)
                  {
                      bool updateAvailable = false;
                      QString newVersion;
                  
                      QNetworkAccessManager *http = new QNetworkAccessManager();
                      QNetworkReply *treply = http->get(QNetworkRequest(QUrl("http://msg.keppe.org/update/stable" + versionType)));
                      QEventLoop loop;
                      QTimer::singleShot(5000, &loop, SLOT(quit()));
                      QObject::connect(treply, SIGNAL(finished()), &loop, SLOT(quit()));
                      loop.exec&#40;&#41;;
                  
                      newVersion = QString::fromUtf8(treply->readAll());
                      newVersion = newVersion.remove("\n");
                      newVersion = newVersion.remove("\r");
                      newVersion = newVersion.trimmed();
                  
                      if (a.applicationVersion() != newVersion && newVersion != "") {updateAvailable = true;}
                  
                      if (updateAvailable)
                      {
                          QStringList args;
                          args.append("/C");
                          args.append("KeppeScriptUpdater.exe --path=network --script=http://msg.keppe.org/update/" + versionType + "_" + newVersion + ".lua --version=" + a.applicationVersion());
                          QProcess *process = new QProcess();
                          process-&gt;startDetached("cmd",args);
                          return 0;
                      }
                  }
                  

                  #endif
                  #endif

                  QSettings settings("Keppe","Keppe Messenger");
                  settings.beginGroup("Style");
                  bool loadCustom = settings.value("Custom",false).toBool();
                  if (loadCustom)
                  {
                      QString style = settings.value("Name","System-defined").toString();
                      if (style != "System-defined")
                      {
                          if (style.trimmed() != "")
                          {
                              a.setStyle(style);
                          }
                      }
                  }
                  settings.endGroup();
                  

                  #ifdef WIN32
                  settings.beginGroup("Update");
                  bool updateNotificationEnabled = settings.value("UpdateNotification",true).toBool();

                  if (updateNotificationEnabled)
                  {
                  
                      frmUpdate *uw = new frmUpdate();
                      uw->setVersionType(versionType);
                  
                      UpdateThread *ut = new UpdateThread(versionType, a.applicationVersion());
                      ut->start();
                  
                      QObject::connect(ut,SIGNAL(setNewVersion(QString)),uw,SLOT(setNewVersion(QString)));
                      QObject::connect(ut,SIGNAL(updateIsNowAvailable()),uw,SLOT(show()));
                      QObject::connect(uw,SIGNAL(disableUpdateNotification()),ut,SLOT(disableUpdateNotification()));
                  
                  }
                  
                  settings.endGroup();
                  

                  #endif

                  frmLogin w;
                  
                  if (minimized) {goto minimized;}
                  
                  w.show();
                  goto appexec;
                  

                  minimized:
                  w.showMinimized();

                  appexec:

                  return a.exec&#40;&#41;;
                  

                  }
                  @

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

                    No need for goto

                    @
                    if (minimized) {
                    w.showMinimized();
                    } else {
                    w.show();
                    }
                    return a.exec();
                    }
                    @

                    I also don't see anything really suspicious. Since you are using K in some of your classes are you using KDE's framework ? Or is it just because of the name of your software ?

                    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
                    • K Offline
                      K Offline
                      KeppePT
                      wrote on last edited by
                      #10

                      I have build my own K Class'es for (K)eppe (I know has KDE have K)
                      I have a Bug with the Visual Studio 2010 Compiler, i have fixed it with Q_DECL_EXPORT and Q_DECL_IMPORT, i testing that on Linux if i have results i edit my post.

                      Edit:
                      No, Q_DECL_EXPORT and Q_DECL_IMPORT is not the Problem on Linux

                      Second Edit:
                      i have resolved this Problem, my KGuiFw used a function is only enabled on Windows, i have used now #ifdef WIN32 to resolve it

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

                        Nice you found out !

                        You should rather use

                        @#ifdef Q_OS_WIN@

                        It will be valid for the various version of windows you might encounter

                        Since it's working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                        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