Extra Double Quotes ("") retrieves from objectName.



  • Hi,

    I'm beginner to the Qt and while studying the Qt course material I got a problem.

    I have 3 files.

    1. valueobject.h

    @#ifndef VALUEOBJECT_H
    #define VALUEOBJECT_H

    #include <QObject>

    class ValueObject : public QObject
    {
    Q_OBJECT

    public:
    explicit ValueObject(QObject *parent = 0);
    virtual ~ValueObject();

    };

    #endif // VALUEOBJECT_H@

    1. valueobject.cpp

    @#include "valueobject.h"
    #include <QDebug>

    ValueObject::ValueObject(QObject *parent) :
    QObject(parent)
    {
    qDebug() << "ValueObject constructed";
    }

    ValueObject::~ValueObject()
    {
    qDebug() << "ValueObject" << this->objectName() << "destructed";
    }@

    3.main.cpp

    #include "valueobject.h"

    @#include <QDebug>
    #include <QFile>

    int main(int argc, char *argv[])
    {
    ValueObject o;
    o.setObjectName("root");

    return 0;
    

    }@

    When I run the program I got the result as

    ValueObject constructed
    ValueObject "root" destructed

    My problem is how extra "" appears in both sides of word 'root'?

    I also tried

    @QString root ="root"
    o.setObjectName(root);@

    but result is same.

    Thanks in advance.



  • thats how QDebug handles QStrings.
    To get it without the double quotes you can do the following:
    @qDebug() << "ValueObject" << this->objectName().toLatin1().data() << "destructed";
    @



  • @ chris17,

    Thank you very much..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.