程序未正确终止

发布于 2024-11-05 06:09:10 字数 1007 浏览 3 评论 0原文

我正在编写一个计算机视觉应用程序(C++ 和 OpenCV)。我正在使用 wxWidgets 为它创建一个 GUI - 这非常简单;按钮按下事件调用跟踪器应用程序来开始。

我终止应用程序的调用(即单击关闭按钮)如下:

// Exiting the App
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

这通常适用于更简单的 GUI 应用程序。然而,这次,框架消失了,在任务管理器中,该进程似乎继续运行并占用内存。这非常烦人,因为如果我运行或调试应用程序,然后进行一些更改并尝试再次运行,而没有事先手动终止进程,编译器会抛出链接错误,因为 .exe 是

最后一个增量链接未找到或未构建。

尝试插入强力出口(1);在 onQuit 方法中,但它会导致应用程序崩溃。

我不确定它是什么..在没有 GUI 的情况下运行时,应用程序运行并正常终止(尽管它的调用方式略有不同 - 来自 main() 函数,而不是来自调用抽象基的按钮按下事件处理程序班级)。

是否有可能是因为类是在全局范围内声明的?例如,在一个文件中我有一个在任何类方法之外声明的类的实例?也许 wxWidgets 无法处理这个问题?

澄清一下:

我要关闭的框架是顶级框架。当它不调用计算机视觉方法时,我对完全相同的 GUI 代码没有任何问题。

我没有专门编写任何多线程代码,但首先,我收到一条错误消息“错误:无法初始化 OLE”。为了解决这个问题,我必须将wxUSE_DRAG_AND_DROP、wxUSE_CLIPBOARD、wxUSE_OLE和wxUSE_OLE_AUTOMATION设置为0(而不是1),然后(重新)编译wxWidgets。

只是想知道 HighGUI 是否存在某种与 WxWidgets 不一致的线程?还有其他人遇到过类似的问题吗?

I'm writing a computer vision app (C++ and OpenCV). I am creating a GUI for it with wxWidgets - this is very simple; a button-press event calls the tracker app to begin.

My call to terminate the app (i.e. on clicking to close button) is as follows:

// Exiting the App
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

This usually works with more trivial GUI apps. However, on this occasion, the frame disappears yet, in the task manager, the process seems to continue running and holding memory. It's very annoying because if I run or debug the application and later make some changes and try to run again, without manually terminating the process beforehand, the compiler throws a link error because the .exe is

not found or not built by the last incremental link.

Tried inserting a brute force exit(1); in the onQuit method but it causes the app to crash.

I'm not sure what it is.. when running without the GUI, the app runs and terminates fine (albeit it is called slightly differently - from the main() function instead of from a button-press event handler which calls an abstract base class).

Is it possible that it is because a class is being declared with global scope? As in, in one file I have an instance of a class declared outside of any class method? Perhaps wxWidgets can't handle this?

To clarify:

The frame I'm closing is a top level frame. I had no problems with the exact same GUI code when it does not call the computer vision methods.

I haven't specifically coded any multi-threading but to begin with, I was getting an error that said "Error: Cannot initialize OLE". To fix this, I had to set wxUSE_DRAG_AND_DROP, wxUSE_CLIPBOARD, wxUSE_OLE and wxUSE_OLE_AUTOMATION to 0 (instead of 1) and then (re)compile wxWidgets.

Just wondering, is there some kind of threading going on with HighGUI that is inconsistent with WxWidgets? Has anybody else encountered similar problems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

第几種人 2024-11-12 06:09:10
::wxExit

void wxExit()

调用 wxApp::OnExit 后退出应用程序。仅应在紧急情况下使用:通常应删除顶级框架(在删除所有其他框架之后)以终止应用程序。参见wxCloseEvent和wxApp。

包含文件

<wx/app.h>

您也可以简单地调用 crt 函数 exit() ,它将立即关闭所有内容。

然而,如果你想要比这些相当残酷的方法更有礼貌(你可能想要这样做,特别是如果你在 wxApp::OnExit 中放置了一些特殊的关闭代码)
)然后你想找到顶层窗口并关闭它。从代码中的任何位置执行此操作

wxGetApp().GetTopWindow()->Close()
::wxExit

void wxExit()

Exits application after calling wxApp::OnExit. Should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to terminate the application. See wxCloseEvent and wxApp.

Include files

<wx/app.h>

You can also simply call the crt function exit() which will instantly shut down everything.

However, if you want to more polite than these rather brutal methods ( which you may want to do in particular if you have placed some special shut down code in wxApp::OnExit
) then you want to find the top level window and close that. To do this from anywhere in your code

wxGetApp().GetTopWindow()->Close()
柠栀 2024-11-12 06:09:10

感谢大家的帮助,我已经解决了问题。现在看来相当明显,但当时却无法弄清楚!

最初,我的计算机视觉应用程序是从主函数调用的。然而,新的 GUI 代码不再需要 main,所以我用 shell 类替换了原来的 main。

尽管我一直小心地释放计算机视觉类的方法中分配的内存,但我对原始的 main 函数并没有那么小心,因为一旦该函数结束,之前使用的所有内存都将被程序的常规退出清除。

与新 GUI 代码的区别在于,当 shell 类完成时 - 程序仍在运行。线索在于,即使计算机视觉应用程序结束,我的网络摄像头上的蓝光仍然闪烁。

* 请务必调用 cvReleaseCapture( &capture );释放该线程并释放硬件*

Thanks for all the help, I have solved the problem. Seems fairly obvious now but couldn't figure it out at the time!

Originally, my computer vision app was called from a main function. However, with the new GUI code there is no need for a main so I replaced the original main with a shell class.

Though I had been careful to free allocated memory within the methods of my computer vision classes I had not been so careful with the original main function because once that function ended, all memory previously in use would be cleared up by the program's regular exiting.

The difference with the new GUI code is that when the shell class is finished - the program is still running. The clue was in the fact that even when the computer vision app had ended, the blue light on my webcam was still shining.

* Be sure to call cvReleaseCapture( &capture ); to free up that thread and release the hardware *

荭秂 2024-11-12 06:09:10

您对 Close 的调用只会关闭框架,但不会停止应用程序,因为它不是最后一个顶级窗口。 wxWidget 包含一个主题窗口删除概述。它指出

当最后一个顶级窗口(wxFrame 或 wxDialog)被销毁时,wxWidgets 应用程序会自动退出。将任何应用程序范围的清理代码放入 wxApp::OnExit(这是一个虚函数,而不是事件处理程序)。

你的框架是顶级框架吗?如果没有,您可能必须在顶级框架上调用CloseDestroy

Your call to Close only closes the frame, but doesn't stop the application, because it is not the last top level window. The wxWidget contains a topic Window Deletion Overview. It states that

A wxWidgets application automatically exits when the last top level window (wxFrame or wxDialog), is destroyed. Put any application-wide cleanup code in wxApp::OnExit (this is a virtual function, not an event handler).

Is your frame the top-level frame? If not, you may have to call Close or Destroy on a top-level frame.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文