Hello All,
I'm trying to implement the following scenario: when user selects the file
using WFileUpload widget, I start upload immediately (using
WFileUpload.changed signal handler) and then upon its completion (in
WFileUpload.uploaded handler) I start to execute some lengthy calculations
with uploaded file.
To provide feedback to the user I attempted to use processEvents() call,
however it leads to the following exception:
[fatal] "Exception while setting resource data
Caused by exception:doRecursiveEventLoop(): inconsistent state"
When processEvents() is not called in "uploaded" handler everything seems
to work fine; if processEvents() is called in any other handler than
"uploaded" things also seem to work fine, so I suspect it may be only this
particular combination of signal and call that is problematic.
In the attach there's "Hello World" Wt example modified to reproduce the
problem.
Environment: wt-2.2.3 on Gentoo/x64, boost-1.36.0, wt is compiled with
FastCGI and whttpd support, the example is executed as follows: "./hello
--docroot . --http-address 0.0.0.0 --http-port 8080"
Is there anything that I'm missing about using this Wt API? Is any
additional information required to determine what is the problem?
Thanks!
--
Good luck! Alexander
/*
* Copyright (C) 2006 Wim Dumon, Koen Deforche
*
* See the LICENSE file for terms of use.
*/
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WFileUpload>
using namespace Wt;
/*
* A simple hello world application class which demonstrates how to react
* to events, read input, and give feed-back.
*/
class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env);
private:
WLineEdit *nameEdit_;
WText *greeting_;
WFileUpload *upload_;
void greet();
void startUpload();
void uploaded();
};
/*
* The env argument contains information about the new session, and
* the initial request. It must be passed to the WApplication
* constructor so it is typically also an argument for your custom
* application constructor.
*/
HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
setTitle("Hello world"); // application title
root()->addWidget(new WText("Your name, please ? ")); // show some text
nameEdit_ = new WLineEdit(root()); // allow text input
nameEdit_->setFocus(); // give focus
WPushButton *b = new WPushButton("Greet me.", root()); // create a button
b->setMargin(5, WWidget::Left); // add 5 pixels margin
root()->addWidget(new WBreak()); // insert a line break
greeting_ = new WText(root()); // empty text
/*
* Connect signals with slots
*/
b->clicked.connect(SLOT(this, HelloApplication::greet));
nameEdit_->enterPressed.connect(SLOT(this, HelloApplication::greet));
upload_ = new WFileUpload(root());
upload_->changed.connect(SLOT(this, HelloApplication::startUpload));
upload_->uploaded.connect(SLOT(this, HelloApplication::uploaded));
}
void HelloApplication::startUpload()
{
greeting_->setText("Uploading ...");
upload_->upload();
}
void HelloApplication::uploaded()
{
greeting_->setText("Uploaded");
processEvents();
}
void HelloApplication::greet()
{
/*
* Update the text, using text input into the nameEdit_ field.
*/
greeting_->setText("Hello there, " + nameEdit_->text());
}
WApplication *createApplication(const WEnvironment& env)
{
/*
* You could read information from the environment to decide whether
* the user has permission to start a new application
*/
return new HelloApplication(env);
}
int main(int argc, char **argv)
{
/*
* Your main method may set up some shared resources, but should then
* start the server application (FastCGI or httpd) that starts listening
* for requests, and handles all of the application life cycles.
*
* The last argument to WRun specifies the function that will instantiate
* new application objects. That function is executed when a new user surfs
* to the Wt application, and after the library has negotiated browser
* support. The function should return a newly instantiated application
* object.
*/
return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest