I am new to QT(jambi). I have a very simple QTJambi (4.5.2) app. I am trying to figure out why this will not work (DoResponseReady never called) within a thread. Switch the static variable between threaded=true/false to reproduce.
import com.trolltech.qt.core.QByteArray;
import com.trolltech.qt.core.QUrl;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.network.QNetworkAccessManager;
import com.trolltech.qt.network.QNetworkReply;
import com.trolltech.qt.network.QNetworkRequest;
public class Main {
static boolean threaded = false;
static Main main;
public static void main(String[] args) {
QApplication.initialize(args);
main = new Main();
main.doit();
}
void DoResponseReady(QNetworkReply reply) {
System.out.println("Response Ready");
}
void testnetwork_thread()
{
new Thread(new Runnable() {
@Override
public void run() {
testnetwork();
}
}).start();
}
void testnetwork()
{
QNetworkAccessManager qnam = new QNetworkAccessManager();
QNetworkRequest req = new QNetworkRequest(new QUrl("http://junkurl.neverwillwork.ok"));
QByteArray data = new QByteArray();
qnam.finished.connect(main, "DoResponseReady(QNetworkReply)");
qnam.post(req, data);
}
void NetworkTest()
{
if (threaded)
testnetwork_thread();
else
testnetwork();
}
public void doit() {
QPushButton quit = new QPushButton("Test");
quit.clicked.connect(this, "NetworkTest()");
quit.show();
QApplication.exec();
}
}