segmentation fault
-
@Milav Did you debug to see whether mosq is not a nullptr? If it's not please provide stack trace after crash.
Also, in connectPressed it does a return if port is not set - is it set if you press connect?
You should really run through debugger... -
i debug the size of mosq pointer through following code.
int size = sizeof(*mosq); qDebug() << size;
and output is 20;
and in connectpressed button slot are run succesfully.
port value are shown correctly.
when i run debugger it shows following error.
The inferior stopped because it received a signal from the Operating System. Signal name : SIGILL Signal meaning : Illegal instruction
hope you got my point.
-
@Milav said in segmentation fault:
i debug the size of mosq pointer through following code.
The size of a pointer is fixed, it doesn't matter whether it contains nullptr or something else.
DoqDebug() << mosq;
instead to see the value of the pointer.
Without stack trace I can't tell you what is going on... -
int size = sizeof(*mosq);
The size of a pointer is fixed,
A slight slip of the tongue there. I think what my colleague @jsulm meant to clarify is:
sizeof(...)
is a compile-time calculation, it does not matter what the value ofmosq
is or what it points at run-time, rather this statement just assignssizeof(qtmosq)
regardless. As he says, show us what is in themosq
. -
when i execute "qDebug() << mosq;" it gives following output.
qtmosq(0xac50b0)I'm not sure this is actually trying to deference the pointer, it may just print its value. I would try something like
qDebug() << mosq->something;
, wheresomething
is some field you know is supposed to exist & be valid in aqtmosq
. Or tryqDebug() << *mosq
(note the*
)?how i see stack trace in qt?
can you please explore me more about stack trace?I don't know how you run in your "Embedded Custom Board", but can you run the app from inside a debugger? then when it seg faults you will see a "stack trace" in the debugger showing the call stack when the fault occurred.
-
@JonB said in segmentation fault:
I'm not sure this is actually trying to deference the pointer
It does not, but I wanted to see its value :-)
Looks like it's not NULL. -
@JonB said in segmentation fault:
qDebug() << *mosq
gives error :-
/home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:54: note: 'qtmosq' is not derived from 'const QFlags<T>'
@JonB said in segmentation fault:
qDebug() << mosq->something
i tried following things and it output are '0'.
- qDebug() << mosq->connect_async(host.data(), port);
- qDebug() << mosq->loop_start();
- qDebug() << mosq->subscribe(NULL, "sensors/temprature", 1);
the output of all above command are zero (0).
@JonB said in segmentation fault:
app from inside a debugge
i am not able to run the debugger because it gives following error.
The inferior stopped because it received a signal from the Operating System. Signal name : SIGILL Signal meaning : Illegal instruction
hope you got your answer.
-
@JonB said in segmentation fault:
@jsulm
Indeedy :) So now let's see how qDebug() << *mosq fares?sorry the error is as following not previous one.
/home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:54: error: no match for 'operator<<' in 'qDebug()() << *((MainWindow*)this)->MainWindow::mosq'
-
@Milav
First you wroteand i debug the application via qDebug(), the application are crash on following line of code.
mosq->subscribe(NULL, "sensors/temprature", 1); // Segmentation falutNow you write
qDebug() << mosq->subscribe(NULL, "sensors/temprature", 1);
the output of all above command are zero (0).This is a problem if you say sometimes it seg faults and sometimes it returns 0? Is that the case? You need to be very specific in your answers!
i am not able to run the debugger because it gives following error.
That is indeed a big problem. There is little for us to answer from what you have posted. Is a debugger supposed to work for your "Embedded Custom Board" (I don't know about this)? You really need one. Otherwise you are likely to have to try printing out all sorts of information in your code to try to diagnose what is going on....
-
Can you try to run the app directly with gdb?
I know this is not the place for a long explanation. But when OP says
I make a qt application for Embedded Custom Board
I thought (knowing nothing about this) it meant he is doing something like )cross-)compiling of whatever but the app runs "on the board", so he might not have/be able to use a debugger? Can you explain to me in one sentence what the OP's enthronement actually is, I'd like to have the vaguest understanding....
-
@jsulm said in segmentation fault:
Forget about
qDebug() << *mosq;okay thank you.
@jsulm said in segmentation fault:
Can you try to run the app directly with gdb?
yes i tried but , debugger give me error,
the error is shown in below image.