Here is my project:
clean.h
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#ifndef CLEAN_H
#define CLEAN_H
Q_OBJECT
public:
explicit Clean
(QObject *parent
= 0); ~Clean
();
//void deleteDir();
//void deleteFile();
Q_INVOKABLE void clean1();
};
#endif // CLEAN_H
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#ifndef CLEAN_H
#define CLEAN_H
class Clean : public QObject {
Q_OBJECT
public:
explicit Clean(QObject *parent = 0); ~Clean();
//void deleteDir();
//void deleteFile();
Q_INVOKABLE void clean1();
};
#endif // CLEAN_H
To copy to clipboard, switch view to plain text mode
clean.cpp
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QFile>
#include <QDir>
#include "clean.h"
void deleteDir(const std::string& foldername) {
dir.remove(foldername.c_str());
}
void deleteFile(const std::string& filename) {
file.remove(filename.c_str());
}
}
Clean::~Clean() {
}
void Clean::clean1() {
deleteDir(e:/data);
deleteFile(e:/qf)
}
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QFile>
#include <QDir>
#include "clean.h"
void deleteDir(const std::string& foldername) {
QDir dir;
dir.remove(foldername.c_str());
}
void deleteFile(const std::string& filename) {
QFile file;
file.remove(filename.c_str());
}
Clean::Clean(QObject *parent) : QObject(parent) {
}
Clean::~Clean() {
}
void Clean::clean1() {
deleteDir(e:/data);
deleteFile(e:/qf)
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "clean.h"
int main(int argc, char *argv[])
{
Clean clean;
QDeclarativeView view;
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.rootContext()->setContextProperty("Clean", &clean);
view.
setSource(QUrl("qml/GCleaner/main.qml"));
return app.exec();
}
#include "clean.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Clean clean;
QDeclarativeView view;
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.rootContext()->setContextProperty("Clean", &clean);
view.setSource(QUrl("qml/GCleaner/main.qml"));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
main.qml
Button {
id:button
onClicked: Clean.clean1()
}
Button {
id:button
onClicked: Clean.clean1()
}
To copy to clipboard, switch view to plain text mode
It works very well on Qt Simulator, but not work on my mobile device. I also tried to add qdir.h and qfile.h but it exited with code -1073741819.
What should I do? Thank you so much for your help.
Bookmarks