I am customizing vlc source code and needed to use QNetworkAccessManager from Qt OpenDialog (part of QT UI dialogs for vlc).
I am trying to use following code sample
void MainWindow::requestShowPage(){
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(requestReceived(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://google.com")));
}
void MainWindow::requestReceived(QNetworkReply* reply){
QString replyText;
replyText.fromAscii(reply->readAll());
ui->txt_debug->appendPlainText(replyText);
}
My primary problem is that vlc fails to load UI even if there is a single call as follows:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
Following is the output produced on vlc console
./vlc
[0x19c9388] main libvlc: Running app with the default interface.
[0x1f82988] main interface error: corrupt module: /VLC/vlc-2.0.4/modules/gui/qt4/.libs/libqt4_plugin.so
[0x2586748] main generic error: corrupt module: /VLC/vlc-2.0.4/modules/gui/qt4/.libs/libqt4_plugin.so
[0x1f82988] skins2 interface error: no suitable dialogs provider found (hint: compile the qt4 plugin, and make sure it is loaded properly)
[0x1f82988] skins2 interface error: cannot instantiate qt4 dialogs provider
[0x1f82988] [cli] lua interface: Listening on host "*console".
Simply omitting the QNetworkAccessManager brings the UI back again.
a. Is there any thing special regarding QNetworkAccessManager usage scenarios i.e. should it be created globally or something? I went through its documentation, but didn't find any thing.
b. Are there any special conventions with respect to Qt or it's use with VLC that i am missing? I am significantly experienced in c/c++ and Linux but new to QT.
UPDATE1: I saw this SO question too which basically is trying to do the same httpget using QNetworkAccessManager. However, i believe calling this one simple api is not required to be done as a separate module (the question attempts writing a new module)? Or is there any such restriction in qt / vlc
UPDATE2: What i suspect so far is that it has something to do with adding a new class to vlc qt ui section. I tried including http example that comes with qt installation with vlc, but see the same behavior. Any guidelines on including a .cpp and .h in vlc ui components would be helpful.
UPDATE 3: I followed as suggested in the answer below and can't seem to make sense out of the following compilation errors. Can any one help?
/usr/include/qt4/QtCore/qobject.h: In copy constructor ‘QNetworkAccessManager::QNetworkAccessManager(const QNetworkAccessManager&)’:
/usr/include/qt4/QtCore/qobject.h:333:5: error: ‘QObject::QObject(const QObject&)’ is private
In file included from /usr/include/qt4/QtNetwork/QNetworkAccessManager:1:0,
from qt4.hpp:39,
from qt4.cpp:37:
/usr/include/qt4/QtNetwork/qnetworkaccessmanager.h:72:24: error: within this context
qt4.cpp: At global scope:
qt4.cpp:192:63: note: synthesized method ‘QNetworkAccessManager::QNetworkAccessManager(const QNetworkAccessManager&)’ first required here
In file included from qt4.cpp:54:0:
============
qt4.hpp contains following added at global scope
#include <QNetworkAccessManager>
extern QNetworkAccessManager NETWORK_MANAGER;
qt4.cpp contains this at global scope
QNetworkAccessManager NETWORK_MANAGER = QNetworkAccessManager();
and then i am accessing in one of the sub classes of qt4
QNetworkAccessManager * qnam = &NETWORK_MANAGER;
UPDATE 4 I also discovered that manually including QtNetwork to the make file was also problematic (although it it didn't complain in compilation for the headers) and vlc ui failed to load. However, when i added it to main vlc configuration file, even the basic local creation of QNetworkAccessManager worked. See this vlc mailing list thread for details