Warnings app is not a QtilitiesApplication.

9 views
Skip to first unread message

Simon Gemmell

unread,
Jan 7, 2013, 12:13:57 AM1/7/13
to qtil...@googlegroups.com
If I use the latest from Git and do:

QtSingleApplication app(argc, argv);
QtilitiesApplication::initialize(); //Make this a Qtilities app.

QtilitiesApplication::setOrganizationName(Globals::companyName_);
QtilitiesApplication::setOrganizationDomain(Globals::domainName_);
QtilitiesApplication::setApplicationName(Globals::applicationName_);

// Initialize the logger:
QtilitiesApplication::applicationSessionPath();
LOG_INITIALIZE();

On startup of the app I still get the warning:
class QString __cdecl Qtilities::CoreGui::QtilitiesApplication::applicationSessionPath(void) Organization name and application name must be set in order to properly use QtilitiesApplication::applicationSessionPath().

Despite the fact I clearly set those.

Is this the best way to feed things back? I realise I'm not using a release and that things are in a state of flux - would you rather I wait until a release?


Jaco Naude

unread,
Jan 7, 2013, 12:47:57 AM1/7/13
to qtil...@googlegroups.com
Hi Simon

It happens because you call QtilitiesApplication::initialize() before setting your organization and application name. I've updated the documentation to make this clearer.

If you do the following is should not give you the error anymore:

QtSingleApplication app(argc, argv);
QtilitiesApplication::setOrganizationName(Globals::companyName_);
QtilitiesApplication::setOrganizationDomain(Globals::domainName_);
QtilitiesApplication::setApplicationName(Globals::applicationName_);
QtilitiesApplication::initialize(); //Make this a Qtilities app.

// Initialize the logger:
LOG_INITIALIZE();

Will you please let me know if that solves it? We also use QtSingleApplication in an application thats built with Qtilities thus I don't expect any issues with it.

The long story about whats happening is:
In Qt4, the way to determine QtilitiesApplication::applicationSessionPath() is to use QDesktopServices which is located in QtGui. For this reason QtilitiesCoreApplication::applicationSessionPath() could not access it. When you call QtilitiesApplication::applicationSessionPath() the first time it sets the session path in QtilitiesCoreApplication as well. The reason that the QtilitiesApplication constructor can't do it for you is because the application and organisation names have not been set yet at that stage. This is the reason for the QtilitiesApplication::applicationSessionPath() call just after your "// Initialize logger" line. 

However, when you use something like QtSingleApplication you need to do the QtilitiesApplication::initialize() which does a QtilitiesApplication::applicationSessionPath() call for you at the end of it. Thus, you don't need the line after the "// Initialize logger" line in your case (notice that I've taken it out of the above code).

In Qt 5 there is a new class called QStandardPaths which is actually located in QtCore, thus there isn't a need to do this type of "hacking". There is an issue on the Qtilities issue tracker which is going to track the work to use this new QStandardPaths class when compiling against Qt 5.

Let me know if you are experiencing any other issues.

Regards,
Jaco




--
To post to this group, send email to qtil...@googlegroups.com
To unsubscribe from this group, send email to
qtilities+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/qtilities?hl=en?hl=en



--
Jaco Naude'

Qtilities: Building blocks for Qt applications.

Simon Gemmell

unread,
Jan 7, 2013, 6:08:29 AM1/7/13
to qtil...@googlegroups.com
Thanks for the detailed response and I can confirm that it works.

I get a similar issue with actions:
"QtilitiesApplication::mainWindow() is required when registering a action manager.<br><br>Proxy actions will not work as intended."

I have something like this:
 QtSingleApplication app(argc, argv);
 QtilitiesApplication::setOrganizationName(Globals::companyName_);
 QtilitiesApplication::setOrganizationDomain(Globals::domainName_);
 QtilitiesApplication::setApplicationName(Globals::applicationName_);
 QtilitiesApplication::initialize(); //Make this a Qtilities app. Note that for Qt4 this has to be after setting org name etc.
 LOG_INITIALIZE();  // Initialize the Qtilities logger.

 MainForm mainForm(mmi, settings);
 ...
 app.setActivationWindow(&mainForm);
 QtilitiesApplication::setMainWindow(&mainForm);         
 mainForm.show(); 

I have tried moving  QtilitiesApplication::initialize(); underneath setMainWindow but to no avail. MainForm is a QMainWindow.

I will post other issues in a seperate thread, but this one seemed related.

Regards,
Simon

Jaco Naude

unread,
Jan 7, 2013, 6:17:51 AM1/7/13
to qtil...@googlegroups.com
Hi Simon

Do you register actions in the constructor of MainForm? The rule here is that you must call QtilitiesApplication::setMainWindow() before registering any actions since all actions needs a parent widget in order to respond to shortcuts, and Qtilities uses the widget set through setMainWindow() to do this. If you need to register actions in the constructor, just call QtilitiesApplication::setMainWindow(this) before registering any actions.

Let me know if this solves the issue.

Cheers
Jaco


Simon Gemmell

unread,
Jan 7, 2013, 6:41:08 AM1/7/13
to qtil...@googlegroups.com
Ah. Yes, that would be it (I didn't think it through, sorry!). Could be trickier than just QtilitiesApplication::setMainWindow(this) since my MainForm has other widgets which get constructed in the initialisation list and therefore also wouldn't be able to add actions... I might have to change them to be pointers and new'd in the body of the c'tor to get around this.

Heh. How about that, it's not a problem. Despite what I said above I don't actually have any non-pointer member widgets (everything's from the .ui file). 

Can confirm that works.

Thanks,
Simon
Reply all
Reply to author
Forward
0 new messages