QT-creator: c++ application break after running several time - c++

I am working on a Qt application which is used as client to send message to a tomcat server. After running the application for like four times to send or retrieve data back, the application breaks with error message
ASSERT: "!isEmpty()" in file** /usr/include/qt4/qtCore/qlist.h, line 282.
When I clicked on it I don't understand what it means. Does it have anything to do with memory allocation?

You try to access an element from a QList that is empty, debug your code and see where you have that access.
In this file it looks that at line 282 the first member function is defined, so you can start with a search in your code to see where you call first and fix it (call first only if the list is not empty), but note that the last, remove and other member function might use that assert, and at that line number it might be a different member function with the version of Qt you are using, so check that too.

Related

Qt5 ini file that needs updating in case of a crash

I'm writing a simple peer to peer instant messenger for a local network. It uses an ini file to parse a UUID to use as an identifier across the network. The ini file is accessed through a QSettings object. I have written functionality to enable multiple instances of the program to be run on the same computer. When the first program is run, it reads the ini file for the first entry and if one exists reads it, and replaces it with "INUSE". When closing, it replaces the key value with the original UUID. If another instance of the program reads the ini file and reads an INUSE as the first key value, it creates another after it, takes it, and puts an INUSE tag on the second key value.
This works fine, however, if the program crashes the UUID that was "INUSE" will be lost and INUSE will remain until manually taken out. How can I account for crashing with a system that accomplishes the same thing?
Ive taken a look at QLockFile but can't wrap my head around exactly how I would implement such a system.
Any comments are appreciated.
The current format of the ini file is as follows:
[uuid]
1={uuid1}
2={uuid2}
while program 1 is executing
[uuid]
1=INUSE
2={uuid2}
and after a normal end of program
[uuid]
1={uuid1}
2={uuid2}
Essentially what I need is a way of preserving data between program executions but also signal to other instances that said data is currently being used.
I think the first thing is to identify why is your program crashing. In order to choose the better solution.
QLockFile allows you to prevent multiple process accesing the same file. So this only will be usefull to you if the program is crashing beacuse of that.
What ever is the reason your program is crashing, I would recomend the use of exceptions to perform the correct actions when this occurs:
try {
// Some of your code
} catch (exception &e)
{
// Some error occured, do something about it.
// Like restoring your UUID.
}
You can read more about exception here, and you can always use the QT version Qexception.
Hope it helps

Cannot Get LXC Container to Start

I am using LXC via the C API, and have simply copied and pasted the example code (as shown in that link, but replacing the main function name with my own). Then calling this from within another block of code in my program, I cannot get the container to start properly.
The call to start simply returns false. If I change the second parameter to start to 0 (implying that lxcinit should be used instead of /sbin/init), then start "succeeds", but the container state is immediately set to STOPPED, and so I cannot attach to the container.
Attempting to get logs by setting:
c->set_config_item(c, "lxc.logfile", "/home/user/lxc-log.log");
c->set_config_item(c, "lxc.logpriority", "TRACE");
c->set_config_item(c, "lxc.console.logfile", "/home/user/lxc-log2.log");
c->set_config_item(c, "lxc.console.logpriority", "TRACE");
Just produces empty files.
Thinking that this may be related to another issue I saw, I also tried setting:
c->set_config_item(c, "lxc.aa_allow_incomplete", "1");
Creating a separate C++ program, and compiling it works like a charm, but when I attempt to call it from within another program, by simply adding a function and calling it (specifically a uni project), I cannot get it to run properly at all.
As it turned out, I was able to solve this issue by disabling two packages that were included as part of the larger project tcmalloc, and asan.

NS-3 with DCE: How to get input at runtime working with my binaries

I'm using ns-3 with direct code execution, working on Ubuntu, and after a while, I got everything to work, but the thing is: I have four nodes with each one binary to run, and some of the binaries take input from me at runtime, via std::cin. (They will then send messages to the other nodes based on the input). I need to get this working inside the ns-3-environment and I couldn't figure out how.
So far, if I start my simulation and it gets to the point where a node with an application starts that is waiting for input (in an endless loop), the whole thing blocks, it doesn't start other applications, it never even stops the simulation. If I just curiously type something and hit enter, it says "relocation error: elf-cache/0/libgcc_s.so.1: symbol dl_iterate_phdr, version GLIBC_2.2.5 not defined in file 0001.so.6 with link time reference" and gives me an exit code 127.
So, naturally I would just find out how to do runtime input in ns3, but I can't find any material on this.
So, I found the solution for file input finally. Maybe it's useful for someone.
std::ifstream config_doc("path/here/file.txt", std::ifstream::binary);
worked for me - if you make sure that your path starts at the designated folder for the ns3-node. For example, if it's the 0th (1st) node, it has to be placed inside the folder files-0, like this:
(...) /source/ns-3-dce/files-0/path/here/file.txt (if you use path/here/file.txt like above). The node always has its home directory in its files-x directory.

Access Violation (Delphi) - except the first run

I have a POS application written in Delphi, which has been working fine until now.
I had to add a webservice client to have some documents validated by the goverment, and even though I had never worked with WebServices/Encryption before, I managed to do it (thanks to the internet really).
When I run the program and create one of those documents, it is perfectly validated (the webservice is accessed, a SOAP envelope with some data is sent, and the response from the server is received without any problems).
The problem is, if I create another document, when I try to validate it I get an "Access Violation at 0x07e7bcb5: read of address 0x00000012".
My validation routine is a function inside a DLL. Before it was inside the DLL, I had all the code inside the main project, but it crashed my program: if I would validate a document, the response would come, but I would get an Access Violation when I terminated the program or if I tried to validate another.
I also tried loading the DLL dinamically, so the validation process would "start from scratch" at each run, but it was useless.
I've been trying to debug this, but I just can't get it. Running step by step, it fails in some line, I comment it out, and the next run it fails in a completely different place.
I tried also EurekaLog, but I couldn't figure out what to do with the info it gave me (I had never worked with it).
Any direction I should be taking?
Thank you very much!
Nuno Picado
EDIT:
I should probably mention what I'm using to access the webservice:
- THTTPReqResp and WinINet for the communication
- IXMLDocument to create the SOAP Envelope
- LibEay32 to encript some data required by the webservice
- TZDB to get the universal time from a web based server
- Capicom 2.0 to load a certificate required for the communication
I use EurekaLog at work, to debug errors that happen at client installations. Here's what you do with the information EurekaLog gives you:
Fairly high up in the report should be one stack trace for every thread in the program. The one on top should be the one in which the error occurred. That's almost always the most important thing in the error log: it tells you exactly what was going on when the exception was raised.
Find the place in your code that corresponds to the top of the stack trace. An access violation means that somewhere, your code tried to access (read, in this case) memory that's not mapped to your program's address space. A bunch of leading 0s means that you're trying to read at an offset from a null pointer. This almost always means one of three things: You're trying to read the value of an object whose value is nil, you're trying to call a virtual method on an object whose value is nil, or you're trying to read an element of a string or dynamic array whose length is 0 (and this is currently represented by a null pointer).
Now that you know what you're looking for, have a look at the code and see if there's any way that that could be happening based on the information you have available.

WriteFile() crashes when trying to carry on multithreading

I am working on an mfc dll that is accessed via a script and all this works fine. I have added a multi-threading component to it and am trying to use the WriteFile() function to write to my serial port, but somehow the WriteFile() function exits the application after the 2nd write command gets executed.
Without the multithreading bit, everything works normally and I can apply as many writefile commands as I want.
Multi-threading: I am using
CreateThread(NULL,0,WorkerThread,this,0,0);
to create my thread. Using "WorkerThread" to carry out the writefile operations described earlier in the background.
Additionally, I need to use the Sleep() function while writing it at intervals defined by me. At the moment, the program just quits when trying to use Sleep(). So, I just removed it for the time being but would need it at a later stage.
Is this a known problem or something with a but-obvious solution?
Update: I have sort of tried to reach somewhere close to the problem but still not been able to resolve it. Apparently it looks like there is some problem with my WriteFile() parameters.
WriteFile(theApp.m_hCom,tBuffer,sizeof(tBuffer),&iBytesWritten,NULL);
It is not taking the sizeof(tBuffer) properly and because of which it is crashing. I checked out the string to be passed, which is exactly equal to what I need to pass but its crashing out the program if I write the code as done above (for WriteFile()). When I keep the stringlength i.e. manually set the sizeof(tBuffer) parameter to 14, then the program runs but the command does not get executed as the total string size of buffer is 38.
CString sStore = "$ABCDEF,00000020,01000000C1200000*##\r\n";
char tBuffer[256];
memset(tBuffer,0,sizeof(tBuffer));
int Length = sizeof(TCHAR)* sStore.GetLength();
memcpy(&tBuffer,sStore.GetBuffer(),Length);
and then sending it with the WriteFile command.
WriteFile(theApp.m_hCom,tBuffer,sizeof(tBuffer),&iBytesWritten,NULL);
This is wrong: sizeof(TCHAR). Since you are using char you should use sizeof(char) instead. TCHAR could be either 1 or 2 bytes...
In the call to WriteFile you should use Length instead of sizeof(tBuffer). Otherwise you'd probably end up with garbage data in your file (which I assume is later read from somewhere else).
I'm guessing its crashing because you are trying to run that directly from your DLL. Write Function looks fine to me and I think if you try to run your program from the Python script ONLY, it should work. I have faced something similar earlier and came to the conclusion of not running my DLL through the debugger but just the script.
Please read this and this for more information.
Hope this helps.
Good Luck!