folibis
folibis

Reputation: 12874

QString empties while passing to function

I have a project written with QT. So far I tested it in Windows without problems. Today I tried to port it to Linux

I downloaded the Qt source tree from qt.gitorius.org. For now it have version 5.2.2. It compiled and installed without problem. Program also compiled without problem. But there was a problem while running. While debugging I found strange behavior. Shortly in code:

Config::Config()
{
    p_path = QApplication::applicationDirPath();
    if(!p_path.endsWith(QDir::separator())) p_path += QDir::separator();
    QString path = p_path + "Settings/config.xml";
    settings = new Settings(path,this); // here path is /opt/myprog/Settings/config.xml
}
Settings::Settings(const QString file, QObject * parent) : QObject(parent)
{
    p_file = file; // file is empty here!!!!   
    p_initialized = false;
    p_autosave = true;
    p_changed = false;

}

When I pass QString value to function it loses its value.

I checked the same code in Windows and it works without problem.

My system:

Upvotes: 0

Views: 157

Answers (1)

There's nothing badly wrong with the code you show, except that you want to pass a const reference to the string, but that's not the cause of the problem. The Settings constructor should have the following signature:

Settings::Settings(const QString & file, QObject * parent)

You should re-run qmake on the project, clean and rebuild it, and try again. If it still doesn't work, then you have a memory bug and the change of the platform simply exposes a latent bug in your code.

Upvotes: 1

Related Questions