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. Segmentation fault (core dumped) on my application
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault (core dumped) on my application

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 3 Posters 10.8k Views
  • 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.
  • jsulmJ jsulm

    So it crashes already before QApplication a(argc, argv);?
    What does ldd PATH_TO_APP output?

    R Offline
    R Offline
    Renn
    wrote on last edited by
    #7

    @jsulm It looks like nothing in my code.

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #8

      One possible reason for the crash is: that wrong libraries (especially Qt libraries) are loaded.
      That's why I asked for ldd PATH_TO_APP output.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • jsulmJ jsulm

        One possible reason for the crash is: that wrong libraries (especially Qt libraries) are loaded.
        That's why I asked for ldd PATH_TO_APP output.

        R Offline
        R Offline
        Renn
        wrote on last edited by
        #9

        @jsulm The point? I do not understand. I have found a mistake, when I delete this code yes no notification Segmentation, but formnya appears twice, the first has entered the root through pkexec, the other is there anything in the gui.
        I mean the following code:
        ui->browse->setIcon(icon);
        ui->browse->setIconSize(pix.size());

        jsulmJ 1 Reply Last reply
        0
        • Hamed.MasafiH Offline
          Hamed.MasafiH Offline
          Hamed.Masafi
          wrote on last edited by Hamed.Masafi
          #10

          Convert

          locate = QApplication::arguments().at(0);
          

          to

          locate = a.arguments().at(0);
          

          and test.
          And your app must be started with at least one argument.

          Remote object sharing (OO RPC)
          http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

          Advanced, Powerful and easy to use ORM for Qt5
          https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

          R 1 Reply Last reply
          0
          • Hamed.MasafiH Hamed.Masafi

            Convert

            locate = QApplication::arguments().at(0);
            

            to

            locate = a.arguments().at(0);
            

            and test.
            And your app must be started with at least one argument.

            R Offline
            R Offline
            Renn
            wrote on last edited by
            #11

            @Hamed.Masafi Not the same between a variable with QApplication? I've done it but to no avail.

            1 Reply Last reply
            0
            • Hamed.MasafiH Offline
              Hamed.MasafiH Offline
              Hamed.Masafi
              wrote on last edited by
              #12

              @Renn No, they are not same. The a with qApp and QApplication::instance() is equal.
              Can you please paste full source (main.cpp, ui_class.cpp and ui_class.h) ?

              Remote object sharing (OO RPC)
              http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

              Advanced, Powerful and easy to use ORM for Qt5
              https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

              R 1 Reply Last reply
              0
              • R Renn

                @jsulm The point? I do not understand. I have found a mistake, when I delete this code yes no notification Segmentation, but formnya appears twice, the first has entered the root through pkexec, the other is there anything in the gui.
                I mean the following code:
                ui->browse->setIcon(icon);
                ui->browse->setIconSize(pix.size());

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #13

                @Renn Well, I think if you don't call ui->setupUi(this) then ui->browse will probably be null and you just dereference a null pointer which leads to the segmentation fault.
                ui->setupUi(this) initializes all the stuff in ui.

                if(getuid() > 0){
                // Here you do not call ui->setupUi(this);!
                pkexec.start("pkexec " + locate);
                pkexec.waitForFinished();
                }
                else{
                ui->setupUi(this);
                }
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Renn Well, I think if you don't call ui->setupUi(this) then ui->browse will probably be null and you just dereference a null pointer which leads to the segmentation fault.
                  ui->setupUi(this) initializes all the stuff in ui.

                  if(getuid() > 0){
                  // Here you do not call ui->setupUi(this);!
                  pkexec.start("pkexec " + locate);
                  pkexec.waitForFinished();
                  }
                  else{
                  ui->setupUi(this);
                  }
                  
                  R Offline
                  R Offline
                  Renn
                  wrote on last edited by
                  #14

                  @jsulm What should I do now? If I put ui-> setupUi (this); before and after, there are still some more than one, the other one did not go through pkexec root, while the other was entering through pkexec root.

                  jsulmJ 1 Reply Last reply
                  0
                  • Hamed.MasafiH Hamed.Masafi

                    @Renn No, they are not same. The a with qApp and QApplication::instance() is equal.
                    Can you please paste full source (main.cpp, ui_class.cpp and ui_class.h) ?

                    R Offline
                    R Offline
                    Renn
                    wrote on last edited by
                    #15

                    @Hamed.Masafi Oh not the same, this is code that really complete the form ui is just testing me so that the application can go through pkexec root. under the code themselves:
                    untitled.h
                    #ifndef UNTITLED_H
                    #define UNTITLED_H
                    #include <QMainWindow>

                    namespace Ui {
                    class untitled;
                    }

                    class untitled : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    explicit untitled(QWidget *parent = 0);
                    ~untitled();

                    private slots:

                    private:
                    Ui::untitled *ui;
                    };
                    #endif // UNTITLED_H

                    untitled.cpp
                    #include "untitled.h"
                    #include "ui_untitled.h"
                    #include <QProcess>
                    #include <QDebug>
                    #include <QFileDialog>
                    extern QString locate;
                    untitled::untitled(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::untitled)
                    {
                    //ui->setupUi(this);
                    qDebug() << getuid();
                    QProcess pkexec;
                    if(getuid() > 0){
                    //ui->setupUi(this);
                    pkexec.start("pkexec " + locate);
                    pkexec.waitForFinished();
                    ui->setupUi(this);
                    }
                    // else{
                    // ui->setupUi(this);
                    // }
                    //Change button to Icon Image

                    QPixmap pix("/home/rnd/untitled/image/image.ico");
                    QIcon icon(pix);
                    //ui->browse->setIcon(icon);
                    //ui->browse->setIconSize(pix.size());
                    

                    }

                    untitled::~untitled()
                    {
                    delete ui;
                    }

                    main.cpp
                    #include "untitled.h"
                    #include <QApplication>
                    QString locate;
                    int main(int argc, char *argv[])
                    {
                    QApplication a(argc, argv);
                    locate = a.arguments().at(0);
                    untitled w;
                    w.show();

                    return a.exec();
                    

                    }

                    1 Reply Last reply
                    0
                    • Hamed.MasafiH Offline
                      Hamed.MasafiH Offline
                      Hamed.Masafi
                      wrote on last edited by
                      #16
                      #include "untitled.h"
                      #include "ui_untitled.h"
                      #include <QProcess>
                      #include <QDebug>
                      #include <QFileDialog>
                      extern QString locate;
                      
                      untitled::untitled(QWidget *parent) : QMainWindow(parent), ui(new Ui::untitled)
                      {
                      	qDebug() << getuid();
                      	QProcess pkexec;
                      	if(getuid() > 0){
                      		//ui->setupUi(this);
                      		pkexec.start("pkexec " + locate);
                      		pkexec.waitForFinished();
                      	}
                      	
                      	ui->setupUi(this);
                      
                      	//Change button to Icon Image
                      	QPixmap pix("/home/rnd/untitled/image/image.ico");
                      	QIcon icon(pix);
                      	//ui->browse->setIcon(icon);
                      	//ui->browse->setIconSize(pix.size());
                      }
                      

                      Remote object sharing (OO RPC)
                      http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                      Advanced, Powerful and easy to use ORM for Qt5
                      https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                      R 1 Reply Last reply
                      0
                      • Hamed.MasafiH Hamed.Masafi
                        #include "untitled.h"
                        #include "ui_untitled.h"
                        #include <QProcess>
                        #include <QDebug>
                        #include <QFileDialog>
                        extern QString locate;
                        
                        untitled::untitled(QWidget *parent) : QMainWindow(parent), ui(new Ui::untitled)
                        {
                        	qDebug() << getuid();
                        	QProcess pkexec;
                        	if(getuid() > 0){
                        		//ui->setupUi(this);
                        		pkexec.start("pkexec " + locate);
                        		pkexec.waitForFinished();
                        	}
                        	
                        	ui->setupUi(this);
                        
                        	//Change button to Icon Image
                        	QPixmap pix("/home/rnd/untitled/image/image.ico");
                        	QIcon icon(pix);
                        	//ui->browse->setIcon(icon);
                        	//ui->browse->setIconSize(pix.size());
                        }
                        
                        R Offline
                        R Offline
                        Renn
                        wrote on last edited by
                        #17

                        @Hamed.Masafi That's the same mas, will appear 2 form as I mentioned earlier..

                        1 Reply Last reply
                        0
                        • R Renn

                          @jsulm What should I do now? If I put ui-> setupUi (this); before and after, there are still some more than one, the other one did not go through pkexec root, while the other was entering through pkexec root.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #18

                          @Renn You should explain better what you actually want to do. Why do you call ui->setupUi(this) only if getuid()>0?

                          if(getuid() > 0){
                          // Do you want to have an UI in this case?
                          pkexec.start("pkexec " + locate);
                          pkexec.waitForFinished();
                          }
                          else{
                          ui->setupUi(this);
                          }
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          R 1 Reply Last reply
                          0
                          • Hamed.MasafiH Offline
                            Hamed.MasafiH Offline
                            Hamed.Masafi
                            wrote on last edited by
                            #19

                            Oh, you'r right, but what is getuid() ??

                            Remote object sharing (OO RPC)
                            http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                            Advanced, Powerful and easy to use ORM for Qt5
                            https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                            jsulmJ 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @Renn You should explain better what you actually want to do. Why do you call ui->setupUi(this) only if getuid()>0?

                              if(getuid() > 0){
                              // Do you want to have an UI in this case?
                              pkexec.start("pkexec " + locate);
                              pkexec.waitForFinished();
                              }
                              else{
                              ui->setupUi(this);
                              }
                              
                              R Offline
                              R Offline
                              Renn
                              wrote on last edited by
                              #20

                              @jsulm Actually I outsmart gui so that I can enter the root through the framework polkit using pkexec in QProcess. When I write code
                              ui->setupUi (this);
                              pkexec.start("pkexec" + locate);
                              pkexec.waitForFinished();
                              form it appears 2, I outsmart menggunakai if else, in part if I enter the command QProcess and else that I enter ui->setupUi(this);
                              When I was running in qt no anything, but when I run through the terminal, at that time I realized that my application that I made it crashes with a notice "Segmentation fault (core dumped)"

                              1 Reply Last reply
                              0
                              • Hamed.MasafiH Hamed.Masafi

                                Oh, you'r right, but what is getuid() ??

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #21

                                @Hamed.Masafi Get user ID (man getuid)

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                R 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @Hamed.Masafi Get user ID (man getuid)

                                  R Offline
                                  R Offline
                                  Renn
                                  wrote on last edited by
                                  #22

                                  @jsulm Now I have to do?

                                  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