Unsolved Segmentation fault (core dumped) on my application
-
When I run the application I have made no such notification is "Segmentation fault (core dumped)" if there is something wrong with the code I create?
Below is the code:
qDebug() << getuid();
QProcess pkexec;
if(getuid() > 0){
pkexec.start("pkexec " + locate);
pkexec.waitForFinished();
}
else{
ui->setupUi(this);
}locate it in the form of a QString data, which I took from main.cpp, code like this:
#include <QApplication>
QString locate;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
locate = QApplication::arguments().at(0);Is there something wrong with the code?
-
Did you try to debug your application to see where exactly it crashes?
-
@jsulm Crash it can not be seen.
-
Build you application in debug mode.
Then set a breakpoint at QApplication a(argc, argv); start debugging and then do step by step in debugger until it crashes.
If it crashes before QApplication a(argc, argv); then try to execute it from command line to see whether you get more information. -
@jsulm I've run my application in debugging mode, I found a notice like this:
The inferior stopped because it received a signal from the Operating System.Signal name :
SIGSEGV
Signal meaning :
Segmentation fault -
So it crashes already before QApplication a(argc, argv);?
What does ldd PATH_TO_APP output? -
@jsulm It looks like nothing in my code.
-
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. -
@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()); -
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. -
@Hamed.Masafi Not the same between a variable with QApplication? I've done it but to no avail.
-
@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) ? -
@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); }
-
@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.
-
@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_OBJECTpublic:
explicit untitled(QWidget *parent = 0);
~untitled();private slots:
private:
Ui::untitled *ui;
};
#endif // UNTITLED_Huntitled.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 ImageQPixmap 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();
}
-
#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()); }
-
@Hamed.Masafi That's the same mas, will appear 2 form as I mentioned earlier..
-
@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); }
-
Oh, you'r right, but what is getuid() ??
-
@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)"