[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    synchronization problem in libkhtml while doing a form submit
From:       Yarram Sunil Kumar <sunilyv () yahoo-inc ! com>
Date:       2004-07-06 16:13:23
Message-ID: 40EACCD3.7090203 () yahoo-inc ! com
[Download RAW message or body]


I am writing an application that embeds libkhtml. In this application i 
am trying to capture the form submit data after fetching the page.

  I wanted to this  synchronously, first fetch the page and then do the 
form submit and i dont want to do this in any slot.  I am using 
QWaitCondition object for synchronization.  For this i have written 
openURL slot,  formSubmit slot and documetComplete slot. Also running 
the kapplication eventloop in separate worker thread (if i run it as 
main thread i cannot do form submit after getting the page)

i got the following error:-
Very strange! got a DCOPReply opcode, but we were not waiting for a reply!

Thanks,
Sunil.

Following is the code details:-


class Worker: public QThread
{
   public:
      Worker()
        {

          QThread::start();
        }

   protected:
      void run()
      {
        a.exec();
      }

};
int c;
char * v[1];
  static  KApplication a(NULL,c, v, "p4" ,false,false);





main()
{

   Worker eventThread; // this starts event loop in worker thread

       
  
// main thread
      jscript->openURL(url) ; //sends an async open call
       jscript->wait(); // wait for it to complete
       htdoc = jscript->getHtmlDocument();
       //cout << htdoc.toHTML();
       DOM::NodeList formNodes = htdoc.getElementsByTagName("form");
      for ( unsigned int i=0; i < formNodes.length(); i++ )
      {
           DOM::HTMLFormElement formnode = node.item(i);
            formnode.submit(); //submit form
       }

       int i;
         cin >>i ; // waiting here
}



class KJScript : public QObject
{
    Q_OBJECT
QWaitCondition m_waitcond;
    public:
        KJScript();
        void openURL(const KURL & );
        int wait(void);
    public slots:
        void ExecScript(const QString &);
        void formSubmit(const char *, const QString& , const 
QByteArray&, const QString&, const QString&, const QString&) ;
        void documentCompleted(void);
        void handleForm(void);
};

 KJScript::KJScript():QObject()
 {


    this->part = new KHTMLPart();
  // KHTMLPart::FormNotification formNfn=KHTMLPart::Before;
     KHTMLPart::FormNotification formNfn=KHTMLPart::Only;
     this->part->setFormNotification(formNfn);
QObject::connect(this->part->browserExtension(), 
SIGNAL(openURLRequestDelayed(const KURL &, const KParts::URLArgs &)), 
this, SLOT(SlotOpenURL(const KURL &)));

 QObject::connect( this->part, SIGNAL( completed() ), this, SLOT( 
documentCompleted() ) );

     QObject::connect( this->part, SIGNAL(formSubmitNotification(const 
char *, const QString& , const QByteAr
ray& , const QString& , const QString& , const QString& 
)),this,SLOT(formSubmit(const char *, const QString&
, const QByteArray& , const QString&, const QString&, const QString&)) );


}



void KJScript::openURL (const KURL &url )
{
      cout <<"Opening url  =="<< url.url()<<endl;
        this->part->openURL(url);
}



void KJScript::SlotOpenURL (const KURL &url )
{
        this->part->openURL(url);
}

void KJScript::formSubmit(const char * action, const QString& url, const 
QByteArray& formData, const QString& target, const QString& contentType, 
const QString&boundary) {
cout << "Submitted Full URI is 
=="<<this->part->htmlDocument().completeURL(url).string();

}

void KJScript::documentCompleted(void)
  {
        this->m_waitcond.wakeAll();
  }

int KJScript::wait(void) {
    this->m_waitcond.wait();
  }








 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic