Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible. You will want to use <a href="http://doc.trolltech.com/4.7/qnetworkaccessmanager.html" rel="nofollow">QNetworkAccessManager</a>, <a href="http://doc.trolltech.com/4.7/qnetworkrequest.html" rel="nofollow">QNetworkRequest</a>, and <a href="http://doc.trolltech.com/4.7/qnetworkreply.html" rel="nofollow">QNetworkReply</a> classes.</p> <p>Here's an (untested) example, but should get you started with retrieving the mime-type of a page using a HEAD request:</p> <pre><code>class TestClass: public QObject { Q_OBJECT public: TestClass(); void run(); public slots: void ready(QNetworkReply * response); protected: QNetworkAccessManager * manager; }; TestClass::TestClass() { manager = new QNetworkAccessManager(this); this-&gt;connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(ready(QNetworkReply*))); } void TestClass::run() { QUrl url("http://www.widefido.com/"); manager-&gt;head(QNetworkRequest(url)); } void TestClass::ready(QNetworkReply * response) { QVariant contentMimeType = response-&gt;header(QNetworkRequest::ContentTypeHeader); qDebug() &lt;&lt; contentMimeType; } </code></pre> <p>NOTE: If the server does not send back a ContentType header, your QVariant will be invalid. So, before using contentMimeType, make sure you check if it is valid first. Then you can convert to a QString for checking against your list of valid mime-types.</p> <p>NOTE: QNetworkRequests are asynchronous, so you'll have to implement a signal-slot relationship for getting the value out of the QNetworkReploy. You can also have a look in <a href="http://qtnode.net/wiki/QxtSignalWaiter" rel="nofollow">QxtSignalWaiter</a> for doing it inline.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload