problem in using Dialog Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

problem in using Dialog

Post by Hossein »

hello, when i get a value from a dialog ( assume the user enters a number and i want to use that number in a function)
how can i send it to another file ( i mean another function in another file ( class declaration file ( e.g. fun.cpp) )?!)
will a Global variable make it in this situation? if i'm planning to use a Global variable, where should i declare it that both dialog and fun.cpp (other files)
can access it ! ? or is there anyway that it directly sends the value to another function to be processed?

---------------------------------
and why cant i execute a dialog in a file rather than Myframe.cpp for example , i mean

i made a dialog to get the data from user!
when i tried to call this dialog in my simpletron.cpp file( this belongs to class simpletron, that is in pure C++, want to replace all of couts and cins with their Wxwidgets counter parts) ! it generated error! but when i used it
in my _2main.cpp like this "

Code: Select all

void _2Frame::OnButton2Click(wxCommandEvent& event)//invokes Execution pane
{
        Execution dialog(this);
        dialog.ShowModal();

}
( i just double clicked on the button, then this appeared and i wrote it between braces")
this works fine. i included the dialog header file in both simpletron.cpp and _2main.cpp, but it doesnt work in simpletron.cpp ! what should i do ?
it gives me the error :error: no matching function for call to `Execution::Execution(SimpleTron* const)'|

thanks in advance
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Re: problem in using Dialog

Post by Disch »

Hossein wrote: how can i send it to another file ( i mean another function in another file ( class declaration file ( e.g. fun.cpp) )?!)
The typical OOP way to do this would be to give your dialog a Get() function of some sort to retreive the user value from the dialog. If you need to send that value to yet another place in the program, you would need a pointer/reference to the object you'd want to send it to, and call a Set() type funciton.

For example if you want to get the number of pies the user wants to bake, you could do something like:

Code: Select all

void MyWindow::PromptUserForPies()
{
  PieDialog dlg(this);
  if(dlg.ShowModal() == wxID_OK)
  {
    numberOfPies = dlg.GetNumberOfPies();  // get number of pies from user-input value in dialog
    someotherwindow->SetNumberOfPies(numberOfPies); // and send that to another window if one needs it
  }
}
Or have someotherwindow call MyWindow::GetNumberOfPies() instead of having MyWindow call a set function. Whichever suits you better.

Generally you want to avoid global variables if you can.
it gives me the error :error: no matching function for call to `Execution::Execution(SimpleTron* const)'|
You're using a constructor for Execution() which takes a SimpleTron* as an argument. In order for this to work, you'd need to have this contructor defined in your class. Assuming Execution is derived from wxDialog, you can put the following in your class definition:

Code: Select all

class Execution : public wxDialog
{
public:
  Execution(wxWindow* parent) : wxDialog(parent,wxID_ANY,wxT("Enter number of pies"))
  {
  }

  ...
};
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

thank you very much , but i didnt understand ! would you explain more ?!
specially
You're using a constructor for Execution() which takes a SimpleTron* as an argument. In order for this to work, you'd need to have this contructor defined in your class. Assuming Execution is derived from wxDialog, you can put the following in your class definition:


Code: Select all

class Execution : public wxDialog
{
public:
  Execution(wxWindow* parent) : wxDialog(parent,wxID_ANY,wxT("Enter number of pies"))
  {
  }

  ...
};
my dialog class is :

Code: Select all

#ifndef EXECUTION_H
#define EXECUTION_H

//(*Headers(Execution)
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#include <wx/button.h>
#include <wx/dialog.h>
//*)

class Execution: public wxDialog
{
	public:

		Execution(wxWindow* parent,wxWindowID id=wxID_ANY);
		virtual ~Execution();

		//(*Declarations(Execution)
		wxButton* Button1;
		wxPanel* Panel1;
		wxStaticText* StaticText1;
		wxButton* Button2;
		wxTextCtrl* TextCtrl1;
		//*)

	protected:

		//(*Identifiers(Execution)
		static const long ID_STATICTEXT1;
		static const long ID_TEXTCTRL1;
		static const long ID_BUTTON1;
		static const long ID_BUTTON_DISCARD;
		static const long ID_PANEL1;
		//*)

	private:

		//(*Handlers(Execution)
		void OnInit(wxInitDialogEvent& event);
		void OnButton2Click(wxCommandEvent& event);
		void OnButton1Click(wxCommandEvent& event);
		//*)

		DECLARE_EVENT_TABLE()
};

#endif
when i tried "

Code: Select all

Execution(wxWindow* parent,wxWindowID id=wxID_ANY,wxT("Enter number of pies"));
instead of

Code: Select all

Execution(wxWindow* parent,wxWindowID id=wxID_ANY);
it gave me couple of errors!
i dont understand it ! what is "wxT("Enter number of pies")"?
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

In the posted example, wxT("Enter number of pies") went in the wxDialog constructor, not in your own constructor.

The error you get means you are trying to pass a parameter of the wrong type. You're passing 'this', which is a '_2Frame', to a constructor expecting a 'wxWindow'. I don't really know what is '_2Frame', but the error message means _2Frame is not a wxWindow so cannot be passed.

Again, I would strongly encourage you to sharpen your C++ skills. I am glad to help you a bit, but I cannot help you if you stumble across every new line of code you need to write.
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

thank you . may be this file help you understand what im doing!
Attachments
SML.zip
(29.55 KiB) Downloaded 105 times
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

thanks every one , instead of using my own dialog , i used wxGetNumberFromUser(), but there are some deficiencies with using this.
first its limitation to 100 as the max number !( i modified the header file and made it 10000, it worked! :D)
and the other one is it can not be negative! ( can deal with it somehow!)

and the last one is its color, shape and size! is there any way to modify its appearance ? changing its color ( background color) and make it alittle bit more stretched!?
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

hello, i have a function like this( in myframe )

Code: Select all

void _2Frame::OnButton1Click(wxCommandEvent& event)//invoks execution
{

        switch ( Operand) 
	{
		case 10:

		statement;    
    		statement;

            Execution dialog(this);
            if(dialog->ShowModal() == wxID_OK)
            {

			wxString str = ExeTextCtrl->GetValue();
			long num;
			str.ToLong(&num);
			temp = num;
             }
                    dialog->Destroy();
	     
	      statement;
	      statement;
		 


}
as it is plain and clear, im trying to execute a dialog that contains a Text control named "ExeTextCtrl".
i ha ve included the dialogs header file i.e. (#include "Execution.h"), but this doesnt work! how can i get such a thing to work
i've tried

Code: Select all

     Execution dialog(this);
     dialog.ShowModal();
this works perfectly .but it just shows the dialog! nothing else i can can do ! i would appreciate your help on this.
( or would you tell me , if i get the number in dialog, how can i send it to myframe for example?)

----------------------------------------------------------------
( for inputting manners , i used a wxGetNumberFromUser() and it works well, but because iwant my application have a consistant look
i want to change it ! and also there are couple of problems with wxGetNumberFromUser() ( like it dont accept negative numbers , its maximum lenghth is 100,etc)
that makes it hard to rely on it! )
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

if you cant help now , i appreciate a sample program that is using dialogs ! and communicates with main frame!
( e.g. sends the data to a function in main frame , or gets some data from main frame! and stuff like this " )
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

if i get the number in dialog, how can i send it to myframe for example?
Use pointers and methods; sorry Hossein, this is basic C++, I won't teach you C++ on this forum.
pretty
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Feb 11, 2009 3:15 am

Post by pretty »

Take a look at:

1) http://www.cplusplus.com/doc/tutorial/pointers.html

2) http://www.zetcode.com/tutorials/wxwidgetstutorial/


Spend some time with reading so you can try to understand how it works, you can't jump into a framework without knowing such things.
Post Reply