Cross platform - PC & Mac
-
Hi All,
I've been working on a Qt based program that will be solely for PC and have been using the MSVC2013 compiler.
I recently got a job to do a database tool that must run both on PC and Mac. Of course Qt is the first place I thought to go because I love it. However it is not as simple as it seems I think:
As a test I made a very simple widgets program on PC. It compiles using 32bit MSVC just fine. No warnings, no errors and it displays a nice little window.
I then simply moved this code over to the mac. Opened Qt there (same version 5.5). Loaded the project and configured for clang64. However attempting to build generates a TON of warnings and actually some errors in some utility files I have.
I get a fair number of:
unknown warning group '-Winconsistent-missing-override', ignored [-Wunknown-pragmas]
Some of the errors puzzle me a bit. I have:
QString name = "tmrStartTimer"; QString args = "tmrStartTimer(args)";
Then I issue:
Trace( QString( "%1(%2)" ) .arg(name).arg(args) );
Trace is a function I have that writes both to qDebug and an application log file. The trace line in this code gives error:
non-const lvalue rference to type 'QString' cannot bind to a temporary of type 'QString'
I generally understand this message and I can fix it by changing the code to actually have a defined variable.
But... I wonder why this is a problem? I do realize compilers differ but this seems like a pain.
So how do you guys handle this kind of stuff cross platform? Do you ended up with a lot of #ifdefs based on platform or do you try to code to the LCD?
A little guidance would be appreciated.
-
Hi,
The ton's of warning has been fixed for 5.5.1 so you shouldn't need to worry about it. How is Trace implemented ?
-
@SGaist said:
Hi,
The ton's of warning has been fixed for 5.5.1 so you shouldn't need to worry about it. How is Trace implemented ?
void Trace( QString &str );
The MSVC2013 compiler thinks this is ok. Clang64 doesn't like it. It wants me to basically do:
QString str = QString( "%1(%2)" ).arg(name).arg(args); Trace( str );
-
Unless you are modifying str in Trace, you should rather use a const reference.
-
Agreed... but it doesn't fix the problem doing that. IE I still for cLang need to extract things out.
But yes... I get lazy sometimes with the const.
-
If you define Trace as:
void Trace( const QString &str );
then this will work on all compiler:
Trace( QString( "%1(%2)" ) .arg(name).arg(args) );
On VS2015, if I compile your code (without the const) with warnings at level 4, I get this:
warning C4239: nonstandard extension used: 'argument': conversion from 'QString' to 'QString &'
note: A non-const reference may only be bound to an lvalueOr you can disable the language extension and VS2015 will give you an error.
So even VS knows it's wrong. For cross-platform, you better stick to standard C++ and avoid platform specific extensions.
-
Interesting... I'll have to check my warning levels on MSVC...
I agree that my code is lacking. IE the const should be there and I am relying upon some automatic conversion. I get this and I will work to correct it.
I will also try and see if my cLang64 likes Trace( const String &str ). I think I tried that and it still bailed but I could be wrong.
Thanks for al the help guys!