> @ N *for sure problem is related to gcc version and qt *.... because if
> run other ubuntu 18.04 with gcc 5.x all work like my develop pc that
> contains gcc 5.5.
It could also be a coincidence, at least my myself quite often make wrong
conclusion then similar errors happen so I use to double checkt.
> Any how now I have other problem related previous post .....
>
> if(counter>=50 && counter<51)
> {
> QTextStream(stdout) << "state_msg try zone" << endl;
> EMC_TASK_SET_STATE *state_msg = (EMC_TASK_SET_STATE
> *)malloc(sizeof (EMC_TASK_SET_STATE));
> QTextStream(stdout) << "spy 1" << endl;
> // state_msg->clear(); /* these not work because try to
> clear empty array? */
> QTextStream(stdout) << "spy 2" << endl;
> state_msg->state = EMC_TASK_STATE_OFF;
> QTextStream(stdout) << "spy 3" << endl;
> state_msg->serial_number = ++emcCommandSerialNumber;
> QTextStream(stdout) << "actual value of state_msg: " <<
> state_msg->state << endl;
> QTextStream(stdout) << "these steps seems right .. now
> try to write" << endl;
> emcCommandBuffer->write(state_msg);
> QTextStream(stdout) << "just write on emcCommandBuffer"
> << endl;
> free(state_msg);
>
> }
>
> counter++;
Most often use C and more seldom C++ so I might make misstake without compiling
it for myself first. Would suggest this code to get rid of malloc(...) function
and initialize variable then declared and as a const if not supposed to change.
if(counter>=50 && counter<51)
{
QTextStream(stdout) << "state_msg try zone" << endl;
EMC_TASK_SET_STATE state_msg();
QTextStream(stdout) << "spy 1" << endl;
state_msg->clear(); /* these not work because try to clear empty array? */
QTextStream(stdout) << "spy 2" << endl;
state_msg->state = EMC_TASK_STATE_OFF;
QTextStream(stdout) << "spy 3" << endl;
state_msg->serial_number = ++emcCommandSerialNumber;
QTextStream(stdout) << "actual value of state_msg: " <<
state_msg->state << endl;
QTextStream(stdout) << "these steps seems right .. now try to write" << endl;
emcCommandBuffer->write(state_msg);
QTextStream(stdout) << "just write on emcCommandBuffer" << endl;
}
counter++;
If I get it correct your code does not work because you allocate memory but
does not create object, C++ have a constructor for this which I conclude from
Linuxcnc code have no parameters.
EMC_TASK_SET_STATE *state_msg = new EMC_TASK_SET_STATE();
...
free(state_msg)
As you free memory at bottom I would suggest to use local variable as in first
example above, then you will not forget to free memory, it also make possible
stack like memory allocation.
EMC_TASK_SET_STATE state_msg();
I use Eclipse then finding declarations is easier even though it does not work
well for C++ or if Linuxcnc code is the problem. Codeblocks might be another
good option if it works.
Nicklas Karlsson
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers