小编Bus*_*ker的帖子

使用new创建Qt QApplication时的分段错误

我有一个程序,其中使用new运算符创建QApplication.它因未知原因而崩溃.我使用RedHat Linux,G ++ 4.8.2,Qt 4.7.2,它是用相同的编译器构建的.

这个源包含许多看似无用但无害的部分,例如带有四个未使用参数的'func'函数.如果我试图删除它们并进一步简化程序,则崩溃不再可以再现,这当然并不意味着问题已经解决.

崩溃发生在函数strlen中,该函数从系统函数XSetCommand调用.添加我自己的简单实现允许我看到strlen收到一个损坏的指针,见下文.

#include <QApplication>
#include <QMessageBox>

void func(void *, void *, void *, void *)  {}

struct Gui
{
  QApplication qApplication;
  Gui(int argc, char ** argv) : qApplication(argc, argv)  {}
};

struct Process
{
  Process(const std::string &, int argc, char ** argv) {
    func(ptr(), ptr(), ptr(), ptr());
    std::string recent;
    std::string path = std::string("Hi!");
    recent           = std::string("Hi!");
    m_message        = std::string("Hi!");
    m_gui = new Gui(argc, argv);
  }
  ~Process()  { delete m_gui; }

  int exec(void) {
    return QMessageBox::warning(0, …
Run Code Online (Sandbox Code Playgroud)

linux qt segmentation-fault new-operator qapplication

6
推荐指数
1
解决办法
3398
查看次数