我是QT(jambi)的新手。我有一個非常簡單的QTJambi(4.5.2)應用程序。我試圖弄清楚爲什麼在一個線程中這不起作用(DoResponseReady從未調用過)。將threading = true/false之間的靜態變量切換爲重現。QTJambi - QNetworkManager從線程不發射信號
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();
}
}
謝謝。雖然我還沒有意識到這是問題,但它有助於指引我走向一個方向。我確認後我會回來的。 – CDSO1 2010-04-14 20:10:22