Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing rvalue reference to QVariant does not work with strings
Forum Updated to NodeBB v4.3 + New Features

Passing rvalue reference to QVariant does not work with strings

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 441 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michalos
    wrote on 19 Jan 2018, 15:28 last edited by michalos
    #1

    Hi,

    I am trying to return a rvalue reference from a function to a QVariant.
    It works for bool and int, but when I pass a string I get an 'invalid' QVariant.

    My function:

    QVariant &&AudioSettings::getValueFromTable(const QString &name)
    {
        QSqlQuery query(_messengerDB);
        auto queryStr = QString("SELECT %1 FROM user_audio WHERE id = 1;").arg(name);
        if(query.exec(queryStr)){
    
            if(query.next()){
                qDebug() << "AudioSettings::getValueFromTable" << query.value(0);  //here I have a correct QString value => QVariant(QString, "Głośniki (USB Audio CODEC )")
                return std::move(query.value(0));
    
            } else {
                qDebug() << "AudioSettings::setValueToTable : No data for '" << queryStr << "'";
                return QVariant();
            }
    
        } else {
            qDebug()<<"AudioSettings::setValueToTable : Error during getting " << name << " form table user_audio.";
            qDebug() << query.lastQuery();
            qDebug() << query.lastError();
        }
        return QVariant();
    }
    

    when I call:

    QString &&AudioSettings::getAudioOut()
    {
        auto value = getValueFromTable("audio_out");  //here I get an invalid QVariant
        return value.isNull() ? QString() : value.toString(); 
    }
    

    What works is:

    int AudioSettings::getRingtoneType()
    {
        auto value = getValueFromTable("ringtone_type");
        return value.isNull() ? 0 : value.toInt();
    }
    

    Does anyone know why?

    1 Reply Last reply
    0

    1/1

    19 Jan 2018, 15:28

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved