1

上传文件后,我试图打印出它的 spoolFileName() 但尽管应用程序运行顺利,但名称的字符串似乎为空。知道哪里错了吗?(不是文件大小,小于50k)

#include <Wt/WApplication>
#include <Wt/WFileUpload>
#include <Wt/WProgressBar>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/Http/Request>
#include <Wt/WString>

using namespace Wt;

class HelloApplication: public WApplication {
public:
     HelloApplication(const WEnvironment& env);

private:

     WPushButton *uploadButton;
     Wt::WFileUpload *fu;
 Wt::WString g;

     void greet();
 void fileUploaded();
};

HelloApplication::HelloApplication(const WEnvironment& env) :
        WApplication(env) {
    root()->addStyleClass("container");
    setTitle("Hello world");       // application title

    fu = new Wt::WFileUpload(root());
    fu->setFileTextSize(50); // Set the maximum file size to 50 kB.
    fu->setProgressBar(new Wt::WProgressBar());
    fu->setMargin(10, Wt::Right);

    // Provide a button to start uploading.
    uploadButton = new Wt::WPushButton("Send", root());
    uploadButton->setMargin(10, Wt::Left | Wt::Right);

    // Upload when the button is clicked.

    uploadButton->clicked().connect(this, &HelloApplication::greet);
}

void HelloApplication::greet() {
    fu->upload();
    uploadButton->disable();
    fu->uploaded().connect(this, &HelloApplication::fileUploaded);
    g = fu->spoolFileName();
}

void HelloApplication::fileUploaded(){                              // application title
    root()->addWidget(new WText(g.value()));  
}

WApplication *createApplication(const WEnvironment& env) {

    return new HelloApplication(env);
}

int main(int argc, char **argv) {
    return WRun(argc, argv, &createApplication);
}
4

1 回答 1

1

我认为假脱机文件的文件名只有在文件上传后才知道。移动

g = fu->spoolFileName();

到 HelloApplication::fileUploaded()。

于 2013-05-30T11:57:14.190 回答