PDA

View Full Version : An Implemented QHttp Object



bhs-ittech
18th August 2006, 13:27
My problem is when I connect one of my login dialog's slots, which is to
be executed when my Conn object has completed it's http request, however
all it does is; making my dialog return Accepted().

I have an object like this:

class Conn : public QHttp {};

and a dialog like this:

class Login : public QDialog, private Ui::login
{
Conn conn;
...
private slot:
void HttpDone(bool err);
};

and in the Login's constructor I call this connect:

if(c==0) {
conn = new Conn;
} else {
conn = c;
}

connect(conn,SIGNAL(done(bool)),this,SLOT(HttpDone (bool)));

Login::HttpDone looks like this:

void
Login::HttpDone(bool err)
{
if(err) { return; }
QTemporaryFile *file;
XmlHnd *hnd = new XmlHnd();
QXmlSimpleReader xml;
xml.setContentHandler(hnd);
if(conn->Data()->size() < 2)
{
file = conn->Data();
QXmlInputSource XFile(file);
if(xml.parse(XFile))
{
if(hnd->srvErr())
{
QMessageBox *mb = new QMessageBox("Helhed",
hnd->getValue("error"),QMessageBox::Critical,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox: :NoButton);
mb->exec();
delete hnd;
return;
} else {
conn->setcid(hnd->getValue("cid"));
delete hnd;
accept();
}
}
}
}

To me it seems like the slot is called at the time it is being connected to the
http's done signal. Is this true, if so how can I make it behave different?

jpn
18th August 2006, 13:45
void QHttp::done ( bool error ) [signal] (http://doc.trolltech.com/4.1/qhttp.html#done)

This signal is emitted when the last pending request has finished; (it is emitted after the last request's requestFinished() signal). error is true if an error occurred during the processing; otherwise error is false.


if(!err) accept();
This looks like erroneous to me. If everything went ok, you accept the dialog and the rest of the code in Login::HttpDone() becomes never executed...

jacek
18th August 2006, 13:46
Do you invoke any conn's methods in that constructor?

bhs-ittech
18th August 2006, 14:00
jacek: only Conn's constructor to make a pointer to it if there isn't one allready.

jpn: thanks, I miss read that one.

Edit: updated the code in HttpDone in my first post.

even with the changes it still accept the dialog almost before it displays it.

jacek
18th August 2006, 14:13
even with the changes it still accept the dialog almost before it displays it.
But is this dialog really accepted or it just closes itself?

bhs-ittech
18th August 2006, 14:40
But is this dialog really accepted or it just closes itself?

with a minor structual change to HttpDone, it should only accept if it recives
valid data from the web server. And it seem to behave that way.

jacek
18th August 2006, 14:44
with a minor structual change to HttpDone, it should only accept if it recives
valid data from the web server. And it seem to behave that way.
I was asking about the dialog itself, not the way HttpDone works.

How do you create that dialog?

bhs-ittech
18th August 2006, 14:46
I was asking about the dialog itself, not the way HttpDone works.

How do you create that dialog?

quote from 'int main(int,char**)

Login *l = new Login;
l->setServer("www.keenan.dk");
l->show();
// l->setFocus();
QMessageBox *mb;
if(l->exec() == QDialog::Accepted)
{
mb = new QMessageBox("Helhed","Login er endnu ikke understøttet.",QMessageBox::NoIcon,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox: :NoButton);
} else {
mb = new QMessageBox("Helhed","Klik på OK for at lukke.",QMessageBox::NoIcon,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox: :NoButton);
}
return mb->exec();
}

jacek
18th August 2006, 14:52
Login *l = new Login;
l->setServer("www.keenan.dk");
l->show();
...
if(l->exec() == QDialog::Accepted)
You don't have to invoke show(), if you use exec().

What does setServer() do?

bhs-ittech
18th August 2006, 14:54
it calls QHttp's setHost

jacek
18th August 2006, 15:08
it calls QHttp's setHost
Only? In that case this "set host" request will be processed immediately and since it is the last request, QHttp::done() will be emitted.

bhs-ittech
18th August 2006, 15:47
Thanks a lot jacek,

I'd be looking for an altanate way of setting the host/server
perhaps with a
Conn *conn = new Conn("<server name>");
and then invoke
Login *l = new Login(conn);