title: Is there a way to convert a base type stored in QVariant without specializing the cast?
body: <p>Let's consider this example:</p>
  
  <pre><code>QVariant v1(1);
  QVariant v2("goofy");
  QVariantList list;
  
  list &lt;&lt; v1 &lt;&lt; v2;
  
  for (const auto&amp; var : list) {
     qdebug() &lt;&lt; var;
  
     // nasty part
     if (var.type == QVariant::Int) {
        int value = var.toInt();
  
        // do something
     } else if (var.type == QVariant::QString) {
        QString value = var.toString();
  
        // do something
     }
  }
  </code></pre>
  
  <p>The debug function shows the internal storage type of <em>QVariant</em>:</p>
  
  <pre><code>QVariant(int, 1) QVariant(QString, "goofy") 
  </code></pre>
  
  <p>Is there a way to avoid the <code>if</code>s and do an explicit cast in order to access the internal type? More specifically, to get the value I would like to be able to write something like this:</p>
  
  <pre><code>auto value = var.ToData();
  </code></pre>
  
  <p><strong>Edit</strong>: Since QVariant can hold a lot of type and you can even add custom types on it, it would be enough restricting the problem only to base types <strong><em>(int, double, bool, string)</em></strong></p>