wxStandardPaths and Console Application [SOLVED]

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
Tony0945
Earned some good credits
Earned some good credits
Posts: 105
Joined: Wed Oct 21, 2009 4:02 pm

wxStandardPaths and Console Application [SOLVED]

Post by Tony0945 »

I'm writing a utility program that converts an XML file to a database. I wish to use the wxwidgets wxXML classes and more. The program does not have a GUI, so I created it as a console application. Because it is to be cross-platform, I used wxStandardPaths to generate the full path names. At run-time, I get an error about using wxStandardPaths without initializing wxApp. I tried creating a Frame application and doing everything at the App OnInit() method and not calling frame->Show(), but that got me a more detailed error about needing to initialize the application first. Besides, creating an empty frame that is never shown is ugly design.

How can I create a console application in wxDev-C++ using all the non-visual classes including wxStandardPaths ?
Last edited by Tony0945 on Thu Dec 24, 2015 2:14 am, edited 1 time in total.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxStandardPaths and Console Application

Post by PB »

I know nothing about wxDev-C++ but if nothing else, it should not stand in your way. Check the console sample bundled with wxWidgets to see how to create wxWidgets console application. And if you want a true console application, make sure to create one (with the proper linker subsystem).

I have just tried with the modified console sample and can confirm that wxStandardPaths works in the console application (latest wxWidgets trunk on MSW).
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxStandardPaths and Console Application

Post by jgrzybowski »

Perhaps you have used wxStandardPaths as a object directly. This statement I have found in docs:
Note that you must not create objects of class wxStandardPaths directly, but use the global standard paths object returned by wxStandardPaths::Get()
and some example form stackoverflow.com:

Code: Select all

bool dialogsApp::OnInit()
{
        wxString xpath;
        xpath = wxStandardPaths::Get().GetExecutablePath();
Regards, Jarek
Tony0945
Earned some good credits
Earned some good credits
Posts: 105
Joined: Wed Oct 21, 2009 4:02 pm

Re: wxStandardPaths and Console Application

Post by Tony0945 »

After a few more hours of googling, I found that the linker message goes away if I include
#include <wx/init.h> and in main() add

Code: Select all

   wxInitializer ini;
However, now when I run, there is no console window and if I run the program by "Start Button->Run->cmd" and navigate to the Output directory and execute the program manually, there is not output and no error messages. Also the program does not pause for keyboard input.

The entire test program is here:

Code: Select all

#include <cstdlib>
#include <iostream>

#include <wx/init.h>
using namespace std;

int main(int argc, char *argv[])
{
    cout << "Press the enter key to continue ...";
    cin.get();
        
    wxInitializer ini;
    
    if (!ini.IsOk())
    {
        cout <<"didn't work";
    }

    return EXIT_SUCCESS;
}
My understanding is that this initialization is called by the wxApp constructor.
I think some library or definitions must be added to the Project options. My question is now, using the wxDev-cpp GUI tool, how can I make the test program work?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxStandardPaths and Console Application

Post by PB »

Tony0945 wrote:After a few more hours of googling, I found that the linker message goes away ...
.
No googling was necessary, the answer was supplied right in the first reply in this thread, i.e. check the console sample. And if you don't see the console window at all (even when running your app from the command line), you may want to check if you don't compile it with "-mwindows" flag. If you do, remove the flag or perhaps just adding "-mconsole" may be enough.
Tony0945 wrote:My question is now, using the wxDev-cpp GUI tool, how can I make the test program work?
I guess virtually no one uses wxDev-C++ in 2015 here on the forums. You are better off asking on their forums.
Tony0945
Earned some good credits
Earned some good credits
Posts: 105
Joined: Wed Oct 21, 2009 4:02 pm

Re: wxStandardPaths and Console Application

Post by Tony0945 »

The -mwindows flag was indeed the problem. Thank you very much.
I guess virtually no one uses wxDev-C++ in 2015 here on the forums. You are better off asking on their forums.
??? This is the wxDev-C++ forum! It's where I've always gone.

I suppose it's time to move on to wxSmith
Post Reply