Debug Assertion Failed CDialog - c++

I have an error in my c++ project. If I clicked "Cancel" or "OK" or "X" buttons program is crashing and display an error like the screenshot.
What could be problem? Here is full code ; http://pastebin.com/54DfqrDb
void CSettingDlg::OnBnClickedCancel()
{
CDialog::OnCancel();
}
void CSettingDlg::OnBnClickedOk()
{
CDialog::OnOK();
}

I fixed this problem. If I declare already don't working a class variable this problem is occurred.
Solution :
//CZipArchive m_ZipArchive; //this class variable is don't working for me

Related

Show accelerator key in menu

I am using Gtkmm 3.22.30 on Ubuntu and I have been trying to show accelerator keys in my application menu, without success. So far, I have been able to register an accelerator key to my menu items, but for some reason, they don't appear in my menu. I know this is possible, because I have seen it in Inkscape, which I believe is using Gtkmm as well (For example: New is bound to <Control>N:
I have prepared a minimal example to show my problem (and what I have done). Here is the code:
#include <gtkmm.h>
#include <iostream>
class MainWindow : public Gtk::ApplicationWindow
{
public:
MainWindow();
private:
void OnActivateSubItem()
{
std::cout << "Handler called" << std::endl;
}
Gtk::MenuBar m_menuBar;
Gtk::MenuItem m_mainMenu{"Menu"};
Gtk::Menu m_menu;
Gtk::MenuItem m_subItem{"Item"}; // Menu|Item
};
MainWindow::MainWindow()
{
// Setting the menu up:
add(m_menuBar);
m_menuBar.append(m_mainMenu);
m_mainMenu.set_submenu(m_menu);
m_menu.append(m_subItem);
// Adding accelerator:
auto accel_group = Gtk::AccelGroup::create();
add_accel_group(accel_group);
m_menu.set_accel_group(accel_group);
// I would have believed this to do the trick but, meh...
m_subItem.add_accelerator("activate",
accel_group,
GDK_KEY_y,
Gdk::ModifierType::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);
m_subItem.signal_activate().connect([this]{OnActivateSubItem();});
}
int main()
{
auto app = Gtk::Application::create("my.menu.problem");
MainWindow window;
window.show_all();
return app->run(window);
}
which leads to the following:
I was expecting a Ctrl + y entry next to the Item menu item (especially with the Gtk::ACCEL_VISIBLE flag for which I have found no documentation), but nothing is showing except a blank space. When I hit Ctrl + y, "Handler called" appears in the console, so the accelerator works.
I have look through the API but it is very confusing and badly documented (I was not able to find a working example for Gtkmm 3.22.30, not even in the examples coming with the source code).
How can I achieve this?
Notes:
I am looking for an answer which does not involve Gtk::Builder if possible.
The answer can use C code if what I want to do is not possible in Gtkmm, but I would need it to integrate with my Gtkmm code.
add_accel_group(accel_group);
m_menu.set_accel_group(accel_group);
I think the same AccelGroup cannot be assigned to a window and a menu. I searched the docs for details on this and found nothing, but my tummy feeling says me you have to delete one of these lines. And in this example they use the AccelGroup only in the window, too. I suggest to delete the second line.
EDIT: i think you are using a different Gtkmm version than i am, because the code you provided works fine on my machine. Could you please compile following c++ program, run it and post its output ?
#include <gtkmm.h>
#include <iostream>
int main() {
cout << gtk_get_major_version() << "." << gtk_get_minor_version() << "." << gtk_get_micro_version();
}

Accessing GUI components through C++ code in VC++

I have created a Windows Form Project in VC++ 2010 Express version. So, in that project I created a Form, which had only 1 button and 1 textbox. The name of this form was Form1.
This button called a function FD written in a .cpp file in the same project. However, while running the code, I need to update the textbox with some text. I want to access the textbox through the .cpp file.
I have tried the following:
I included #include "Form1.h" and then wrote textBox1->Text="XYZ". However, while building it says that it cannot find any member called textBox1.
How do I access the textbox from the .cpp file?
EDIT:
FD.cpp
#include<stdafx.h>
#include "Form1.h"
... //other includes
void abc()
{
//Some code
textBox1->Text="String to be displayed."
//Some code
}
Form1.h
This is simple GUI form, where a button called button1 and a textbox called textBox1 is added.
#include<FD.h>
//code generated by the GUI
void button1_click()
{
abc();
}
// FD.cpp
void abc(Form1^ f)
{
// Assuming that textBox1 is public. If not, make it public or make
// public get property
f->textBox1->Text="String to be displayed."
//Some code
}
// Form1.h
void button1_click()
{
abc(this);
}
Or:
// FD.cpp
void abc(TextBox^ t)
{
t->Text="String to be displayed."
//Some code
}
// Form1.h
void button1_click()
{
abc(textBox1);
}
Another way: make abc method return type String^ and set its return value in Form1 to textBox1. Advantage: abc doesn't know anything about UI level. Yet another way: events http://msdn.microsoft.com/en-us/library/58cwt3zh.aspx
The reason you're getting this error is because you haven't specified whose textBox that is. It is not enough to #include the header file, you need to find a way to communicate with your Form1 object. You can do this in several ways.
Using a global pointer to the instance of your main Form1 that can be accessed from anywhere,
Using a local pointer to the instance of your main Form1 that is passed around and can be called upon,
Providing a friend function that can manipulate the data in the class (not recommended),
I would choose 2.

Void Functions, cout statements, and compilers

This is something I have noticed and I do not have the answer to it and it bothers me.
Let's say we have two simple functions.
void foo()
{
std::cout << "Rainbows are cute!" << std::endl;
return;
}
int main()
{
foo();
return 0;
}
Now these two functions are all part of the same cpp file.
If I compile this cpp file on gcc the file will cout "Rainbows are cute!"
but if I were to do it on Xcode or Visual Studio, the cout statement will not display. I mention VS and Xcode because these are two common compilers, used by many.
My question is why does this happen? What is going on in the compilers were one will display the cout statement in the void functions and the others will not?
The printouts will display in VS and Xcode as well. The difference is in how you run this. When you execute your program from Visual Studio, console window briefly pops up, displays the message, and promptly disappears.
To prevent this from happening, you can set breakpoint on return 0 line, and run in debug mode. When the breakpoint is hit, switch to the console window to see the message:

wxWidgets Seg fault on close

My files look something like so:
main.cpp
...
bool SyncApp::OnInit(){
SetTopWindow(new syncWindow(_("(S)FTP Automatic Sync")));
GetTopWindow()->Show(true);
return true;
}
...
syncwindow.h
#include <wx/wx.h>
class syncWindow : public wxFrame {
public:
syncWindow(wxString title) : wxFrame(NULL, -1, title) { initialize(); }
private:
void initialize();
wxTextCtrl * serverEntry;
};
syncwindow.cpp
void syncWindow::initialize(){
serverEntry = new wxTextCtrl(this, wxID_ANY);
this->AddChild(serverEntry);
}
For whatever reason whenever I close the window I get a segfault. If I don't add the serverEntry as a child to the window I don't get a segfault. I don't see why this is doing such a thing. I'm on CentOS 6, g++ 4.7 and wxGTK 2.8. Does anyone have any idea or a hint as to why this is happening?
Since you specified the parent window when constructing your child, the link is already present and calling this->AddChild(serverEntry); will cause double free or similar error when you close the window. http://docs.wxwidgets.org/2.8/wx_wxwindow.html#wxwindowaddchild
wxWindow::AddChild
Adds a child window. This is called automatically by window creation
functions so should not be required by the application programmer.
Notice that this function is mostly internal to wxWidgets and
shouldn't be called by the user code.

dialogbox in a MFC program

i have written the following application using MFC in visual c++ that includes two resources (a menu and a dialogbox) (created using the resource editor)...the program works absolutely fine except that it displays only one resource ie. it displays only the menu but it does not display the dialogbox...
what to do??
this is the code...
#include<afxwin.h>
#include"stdafx.h"
#include"resource.h"
class mydialog:public CDialog
{
private:
int id;
public:
mydialog(int n):CDialog(n)
{
id=n;
}
int OnInitDialog()
{
CDialog::OnInitDialog();
if(id==IDD_DIALOG1)
CenterWindow(GetDesktopWindow());
else
CenterWindow();
return TRUE;
}
void OnOK()
{
CDialog::OnOK() ;
MessageBox(TEXT("You have Pressed the OK Button"),TEXT("OnOK handler"));
}
};
class myframe:public CFrameWnd
{
public:
myframe()
{
Create(0,TEXT("Simple Dialog Box"),WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(IDR_MENU1));
}
void about()
{
mydialog d(IDD_DIALOG1);
d.DoModal();
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_COMMAND(101,about)
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(3);
m_pMainWnd=p;
return 1;
}
};
myapp a;
Hey, without compiling the code and running it I can see a problem here:
myframe()
{
Create(0,TEXT("Simple Dialog Box"),WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(IDR_MENU1));
}
Where you are creating a window using IDR_MENU1 resource which is a menu. This means that the main window of your app is the menu.
Also, the whole code does not look MFC-ish at all. I would suggest creating an MFC app from Visual Studio template - it will set up the main window properly for you.
The dialog will only be displayed when the command with id 101 is executed. Presumably this would be a menu item which is associated with the main window. If your menu is defined as:
IDR_MENU1 MENU
BEGIN
POPUP "HELP"
BEGIN
MENUITEM "About", ID_HELP_ABOUT
END
END
And ID_HELP_ABOUT is defined with the value 101, then your about function will get called when you select that menu item, showing the dialog.
I'm not sure exactly what you are trying to achieve here, and would echo the other suggestions here by saying to start out with the MFC wizard generated code and take it from there.