Tuesday, 15 June 2010

c++ - Qt unable to access object data from my function -



c++ - Qt unable to access object data from my function -

my code compiles error free output little lcd panel have should read 22. reads number 44 initial value set in constuctor. failing update new value. appears mainwindow::finishedslot(qnetworkreply* reply) not beingness accessed , ui->lcdnumber->display(22) not update object expected. can confirm connection establish, have wireshark running , can see software seek , reach google, nil lcd can working because cannot access constructor object. purpose of lcd reflect connection information, right trying reach constructor.

//mainwindow.cpp

#include "mainwindow.h" #include "ui_mainwindow.h" #include <qnetworkaccessmanager> #include <qurl> #include <qnetworkrequest> #include <qnetworkreply> #include <qimagereader> #include <qlcdnumber> #include <qdebug> mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) { ui->setupui(this); nam = new qnetworkaccessmanager(); ui->lcdnumber->display(44); } mainwindow::~mainwindow() { delete ui; } void mainwindow::connect() { qdebug() << "connect"; qobject::connect(nam, signal(finished(qnetworkreply*)), this, slot(finishedslot(qnetworkreply*))); qobject::connect(nam, signal(finished(qnetworkreply*)), this, slot(on_pushbutton_clicked())); } void mainwindow::requestpage(){ qurl url("http://www.google.com"); qnetworkreply* reply = nam->get(qnetworkrequest(url)); } void mainwindow::finishedslot(qnetworkreply* reply){ qdebug() << "finishedslot"; qvariant statuscodev = reply->attribute(qnetworkrequest::httpstatuscodeattribute); qvariant redirectiontargeturl = reply->attribute(qnetworkrequest::redirectiontargetattribute); qbytearray bytes = reply->readall(); // bytes qstring string(bytes); // string ui->lcdnumber->display(22); // if (reply->error() == qnetworkreply::noerror) // { // qimagereader imagereader(reply); // qimage pic = imagereader.read(); // qbytearray bytes = reply->readall(); // bytes // qstring string(bytes); // string // ui->lcdnumber->display(22); //qdebug()<<string; // } // else // { // } } void mainwindow::on_pushbutton_clicked() { requestpage(); }

//mainwindow.h

#ifndef mainwindow_h #define mainwindow_h #include <qmainwindow> #include <qobject> #include <qnetworkaccessmanager> namespace ui { class mainwindow; } class mainwindow : public qmainwindow { q_object public: explicit mainwindow(qwidget *parent = 0); ~mainwindow(); private: ui::mainwindow *ui; public slots: void connect(); void requestpage(); void finishedslot(qnetworkreply* reply); void on_pushbutton_clicked(); private slots: private: qnetworkaccessmanager* nam; }; #endif // mainwindow_h

//main.cpp

#include "mainwindow.h" #include <qapplication> int main(int argc, char *argv[]) { qapplication a(argc, argv); mainwindow mconnect; mconnect.show(); homecoming a.exec(); }

maybe it's me, seems there's no connection between button clicked signal , on_pushbutton_clicked slot.

c++ qt

No comments:

Post a Comment