How to ignore wxCmdLineParser ?  [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.
User avatar
saifcoder
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Nov 16, 2017 9:32 pm

How to ignore wxCmdLineParser ?

Postby saifcoder » Wed Jun 06, 2018 6:59 pm

I want parse command arguments myself, i can get correctly argc and argv

Code: Select all

bool MyApp::OnInit()
{
    ... wxApp::argc ;
    ... wxApp::argv[2] ;
}


but i get wxCmdLineParser error message :
Unexpected paramter 'TestArg1'
Usage: minimal [/h] [--verbose]
/h, --help show this help message,
--verbose generate verbose log message.


i read many topics, google.., but i didn't find a way to ignore wxCmdLineParser

How to ignore command arguments Parser (wxCmdLineParser) please ?

Thanks,
Last edited by saifcoder on Wed Jun 06, 2018 9:57 pm, edited 1 time in total.
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore command arguments Parser ?

Postby saifcoder » Wed Jun 06, 2018 7:00 pm

its a GUI application ^_^
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
doublemax
Moderator
Moderator
Posts: 12604
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to ignore command arguments Parser ?

Postby doublemax » Wed Jun 06, 2018 7:12 pm

Don't call wxApp::OnInit() from inside your overloaded MyApp::OnInit().
Use the source, Luke!

User avatar
saifcoder
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore command arguments Parser ?

Postby saifcoder » Wed Jun 06, 2018 9:44 pm

Thank you for your replay Doublemax, but i didn't call wxApp::OnInit() from MyApp::OnInit() !

Where you see this call ? ^_^

I get this error because i run the app with test arguments (MyApp.exe ArgTest1 ArgTest2...), so the command arguments Parser (wxCmdLineParser) return unknow argument "ArgTest1"

I know, i can use the wxCmdLineParser... but is there i way to ignore this ? i want use my personal parser method !

Thank you,
Last edited by saifcoder on Wed Jun 06, 2018 9:58 pm, edited 1 time in total.
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
doublemax
Moderator
Moderator
Posts: 12604
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to ignore command arguments Parser ?

Postby doublemax » Wed Jun 06, 2018 9:58 pm

Where you see this call ? ^_^
I didn't see it, but it assumed is was there, because that's where the command line parsing happens. And removing it usually gets rid of the message.

Which platform and wxWidgets version are you using?

Try overriding wxAppConsole::OnCmdLineError(...)
http://docs.wxwidgets.org/trunk/classwx ... aac70e3144
Use the source, Luke!

User avatar
saifcoder
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore wxCmdLineParser ?

Postby saifcoder » Wed Jun 06, 2018 10:13 pm

I am using Github master branch (wxWidgets 3.1.1), on Windows (TDM GCC) right now, but i m sure the same result on Linux and Mac..

Code: Select all

class MyApp : public wxApp
{
    public:

   MyApp();
   ~MyApp();
   virtual bool OnInit();
        virtual int OnExit();

   private:
      DECLARE_NO_COPY_CLASS(MyApp)
};

bool MyApp::OnInit()
{
   if (!wxApp::OnInit())
      return false;

   if (wxApp::argc > 1)
   {
      wxString Arg = wxApp::argv[2] ...
   }

    return true;
}


Thanks,
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore wxCmdLineParser ?

Postby saifcoder » Wed Jun 06, 2018 10:26 pm

Yes, wxAppConsole::OnCmdLineError() with true return did it, but after showing error message ! Waw!

Unexpected parameter 'TestArg1'

Then App continue in normal way because wxAppConsole::OnCmdLineError() return true, so how to completely prevent wxAppConsole::OnCmdLineError() to show error log ?
Last edited by saifcoder on Wed Jun 06, 2018 10:29 pm, edited 1 time in total.
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
doublemax
Moderator
Moderator
Posts: 12604
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to ignore wxCmdLineParser ?  [SOLVED]

Postby doublemax » Wed Jun 06, 2018 10:28 pm

Code: Select all

   if (!wxApp::OnInit())
      return false;
What's that? You said you didn't call it.

Set a breakpoint at the beginning of MyApp::OnInit and single step through it. I can't think of any other place where the command line parsing could happen.
Use the source, Luke!

User avatar
saifcoder
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Nov 16, 2017 9:32 pm

Re: How to ignore wxCmdLineParser ?

Postby saifcoder » Wed Jun 06, 2018 10:33 pm

Oh! Not me, but someone else*.. what a bad programmer.., but don't worry i remove it, now with OnCmdLineError() work correctly !

Thank you Doublemax, you save my day ^_^

*saifcoder
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.


Return to “C++ Development”

Who is online

Users browsing this forum: raananb and 24 guests