0

I have a strange problem. My tool is running properly when I open a file through my Qt file dialog. However, when I bind dlls from other library into my project in VS 2010, the tool crashes when I open a file. By debugging I discovered that it happens in the destructor of the basic string. The following line is causing the problem:

std::string inputFilename = aFilenames.at(i).toStdString();

where aFilenames is a QStringList. If instead I write:

std::string inputFilename = "C:\\test.txt";

then it works. What is then going wrong with std::string and why this happens when I bind dlls from another library into my project?

9
  • 1
    Are you sure that your specific string at location i exists? You're not reading somewhere beyond the vector/array? Commented Oct 24, 2012 at 10:20
  • I cannot reproduce the problem, you need to provide more information. Commented Oct 24, 2012 at 10:22
  • Yes, I am sure that I am not out of bound. I could see it in the debugger. Anyway, if I do not bind the dlls, it works.. . The problem arises when I bind the dlls (third party libraries). But what is the difference between my first statement and the second statement? They are both std::strings... Commented Oct 24, 2012 at 10:27
  • 1
    Another suggestion, convert string to C string (char array with \0 a the end), and then the C string to std::string (assuming your filename does not have any non-ASCII chars). Commented Oct 24, 2012 at 10:36
  • 1
    @ISTB Hard to quess what the problem was without seeing intermediate values (debug output, I mean). It may have been some esoteric character encoding issue related to current default encoding, either at Qt or at STL side. Commented Oct 24, 2012 at 11:53

1 Answer 1

1

Try this:

string(aFilenames.at(i).toLocal8Bit())
Sign up to request clarification or add additional context in comments.

2 Comments

I am not sure, but my windows program has no problem with numerous tests since using it.
How does QByteArray ended as const char[]? upd (That's just obvious, doesn't it?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.