FUSE(用户空间文件系统)与 Qt 编程
我正在尝试将 FUSE 与 Qt 一起使用,但 fusion_main() 和 app.exec() 有自己的事件循环。这意味着如果我启动一个,另一个将不会启动,因为第一个启动会阻止另一个启动,如下所示。这该如何处理呢?
有关熔断器的更多信息,请访问 http://fuse.sourceforge.net/
如果可能的话,提供例子。
谢谢你, 莱安德罗.
示例:
这个将阻止fuse启动:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); // qt event loop
a.exec();
fuse_main(argc, argv, &hello_oper); // fuse event loop, it will not start
return 0;
}
而这个将阻止qt启动:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); // it will not start due to fuse_main invocation
fuse_main(argc, argv, &hello_oper);
return a.exec();
}
I'm trying to use FUSE with Qt, but fuse_main() and app.exec() has their own event loop. This mean that if I start one the other will not start, since the first that starts prevents the other to start as shown below. How to deal with this?
For more info about fuse, go to http://fuse.sourceforge.net/
Please, if possible, provide example.
Thank you,
Leandro.
Example:
this one will prevent fuse to start:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); // qt event loop
a.exec();
fuse_main(argc, argv, &hello_oper); // fuse event loop, it will not start
return 0;
}
and this one will prevent qt to start:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); // it will not start due to fuse_main invocation
fuse_main(argc, argv, &hello_oper);
return a.exec();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在单独的线程上运行文件系统。
You should run the filesystem on a separate thread.
您还可以在单独的进程上运行 FUSE,并通过套接字/管道/RPC/...进行通信。如果 FUSE 崩溃或正忙于执行某些操作,您的 GUI 仍然可以工作,这是首选。
You can also run FUSE on a separate process and communicate via sockets/pipes/RPC/... It is preferred in the case that FUSE crashes or is busy doing something, your GUI is still working.
我创建了一个简单的示例来说明如何一起使用 FUSE 和 Qt,请参阅:
https://github.com/qknight/qt-fuse-example
无法使用 fusion_main(..) 便利函数,因为那样您将无法执行以下操作:
- 重新路由 posix 信号
- 您无法轻松关闭熔断过程,就像使用 QFuse.cpp 一样:
fusion_unmount(TUP_MNT, fs.ch);
pthread_join(fs.pid, NULL);
正如 fusion-devel 邮件列表中所讨论的,有两种将 FUSE 集成到 Qt 中的好方法:
实现它(就像我在 qt-fuse 中所做的那样):
Qt mainloop 正在运行,FUSE mainloop 也在运行,两者都在不同的线程中。我解决了有关 POSIX::signal 到 Qt::signal 转换的一些问题,因此可以明确关闭。
修改 FUSE 库以从 Qt 事件循环直接访问:
Qt 主循环正在运行,不需要 FUSE 主循环,因为它将集成到 Qt 主循环中。没有研究这一点,但它可能有不同的优点。
希望这有帮助
i've create a simple example of how FUSE and Qt can be used together, see:
https://github.com/qknight/qt-fuse-example
the fuse_main(..) convenience function can't be used as then you would not have any means of:
- reroute the posix signals
- you can't shutdown the fuse process easily, like with using QFuse.cpp:
fuse_unmount(TUP_MNT, fs.ch);
pthread_join(fs.pid, NULL);
as discussed on the fuse-devel mailinglist, there are two good ways to integrate FUSE into Qt:
implement it (as i did in qt-fuse):
Qt mainloop is running, FUSE mainloop is also running, both in different threads. i solved some issues in regards to POSIX::signal to Qt::signal conversion, so a clear shutdown is possible.
modify the FUSE library to have direct access from the Qt event loop:
Qt mainloop is running, no need for a FUSE mainloop as it would be integrated into the Qt mainloop. didn't look into this but it might have different advantages.
hope this helps