QString/return: Schlaues Vorgehen?

  • C++/CLI

Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von ~blaze~.

    QString/return: Schlaues Vorgehen?

    Hallo,

    ich wollte mal fragen ob das eigentlich schlau ist folgendes zu tun:

    C-Quellcode

    1. QString value_storage::get_value_from_st (const QString &val_id) {
    2. if (!vs_exists()) {
    3. return QString("NULL");
    4. }

    undzwar dieses return QString("NULL");. Irgendwie kommt mir das nicht richtig vor, aber es klappt. Gibt es da etwas schlaueres/besseres? Folgendes ist aus der Qt Dokumentation:

    Quellcode

    1. QString ()
    2. QString ( const QChar * unicode, int size )
    3. QString ( const QChar * unicode )
    4. QString ( QChar ch )
    5. QString ( int size, QChar ch )
    6. QString ( const QLatin1String & str )
    7. QString ( const QString & other )
    8. QString ( const char * str )
    9. QString ( const QByteArray & ba )


    Grüße,
    Jan
    Software being "Done" is like lawn being "Mowed". (Jim Benson)
    Was soll das return QString("NULL") bezwecken?
    Alao mit dem Wert String "NULL"
    Wenn du einen Status zurückgeben willst, dann kannste entweder ein Struct oder besser Enum verwenden. Alternativ einfach bool. Ob vorhanden oder ned vorhanden
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    @Radinator

    Damit ich hinterher beispielsweise folgendes tun kann:

    C-Quellcode

    1. QString some_str = this->get_value_from_st("test");
    2. if (some_str == "NULL") {
    3. //... irgendwas machen
    4. }

    Aber das mit enum/struct wäre gar nichtmal so schlecht.
    Software being "Done" is like lawn being "Mowed". (Jim Benson)
    Also damit ich das richt verstehe: Dir geht es darum, wie man am besten eine QString instanz mit Inhalt erstellt?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell