我的myApp类中有一个<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:background="@color/colorPrimary">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_share_black_24dp"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
成员变量。
该变量将使用CTaskBarIcon *m_pTaskbar
对象的实例。
从CTaskBarIcon
方法中删除m_pTaskbar
时,退出程序时会发生运行时错误,问题的原因是删除onExit
变量。
app.h
m_pTaskbar
app.cpp
#include "taskBarIcon.h"
class myApp: public wxApp{
public:
// ....
private:
CTaskBarIcon *m_pTaskbar; // = NULL
};
CTaskBarIcon.cpp
int myApp::OnExit() {
if (m_pTaskbar != NULL) {
delete m_pTaskbar; // <-- The problem here
m_pTaskbar = NULL;
}
return 0;
}
int myApp::OnRun() {
mainFrm *_mainFrm = mainFrm::getInstance(); // The main window
_mainFrm->Show(false);
m_pTaskbar = new CTaskBarIcon(_mainFrm);
m_pTaskbar->SetIcon(wxIcon("appIcon"), _mainFrm->GetTitle());
return wxApp::OnRun();
}
我的代码是否有问题?
答案 0 :(得分:0)
从自己的事件处理程序中删除wxTaskBarIcon
可能有问题。您是否可以尝试使用CallAfter([this] { Destroy(); })
而不是直接调用Destroy()
直接解决问题?