Deprecation warning in Qt 6.2.3 - qt

I migrated my code from Qt 5.15 to Qt 6.2. I've figured out all of the major issues and everything is working correctly. I've almost figured out all of the warnings, except for one. My original code is
if (PhaseEncodeAngle == "") q3.bindValue(":PhaseEncodeAngle", QVariant(QVariant::Double)); /* for null values */
else q3.bindValue(":PhaseEncodeAngle", PhaseEncodeAngle);
which produces the warning
warning: ‘QVariant::QVariant(QVariant::Type)’ is deprecated: Use the constructor taking a QMetaType instead.
Applying the fix that Qt documentation suggests, the code becomes
if (PhaseEncodeAngle == "") q3.bindValue(":PhaseEncodeAngle", QVariant(QMetaType::Double)); /* for null values */
else q3.bindValue(":PhaseEncodeAngle", PhaseEncodeAngle);
but now this produces an error
error: use of deleted function ‘QVariant::QVariant(QMetaType::Type)’
How can I fix the original warning?

Related

PyQt5 QTableView cell editing behaviour - superimposition of original value

I'm messing around with tables in PyQt for the first time and am running into some unexpected behaviour when editing cell values.
Specifically when I type data, it appears over the top of the existing cell data (so if the cell originally had '123' in it, and I type '456', I end up with 2 lots of 3 characters, one over the top of the other - at least until I press enter).
Just to be clear, I have no issues with setData writing the changes to the model, or with the changes being reflected in the table after editing is complete - that's all happening fine. The only problem is seeing the original value and the new value I'm typing in occupying the same space until editing finishes.
So presumably what I want to do is alter my existing data method:
def data(self, index, int_role=None):
row = index.row()
column = index.column()
if int_role == QtCore.Qt.DisplayRole:
return str(self._data[row][column])
elif int_role == QtCore.Qt.EditRole:
return str(self._data[row][column])
else:
return None
so that it somehow recognizes if the cell it's being asked to provide data for (in DisplayRole mode) is currently being edited, and if so, return an empty string instead of the actual data (as the EditRole branch of the code is being called as well at the same time and is happily handling display duties until editing is finished).
I've had a look around the QT docs but cannot work out how to do this.
Edit: After ceppo's comments, I've looked at creating a new ItemDelegate - but looking into it further it looked like I would be able to instead switch out the itemEditorFactory in the existing one - specifically I added the following to my code:
newEditor = QLineEdit()
newEditor.setAutoFillBackground(True)
ief = QItemEditorFactory()
ief.registerEditor(QVariant.String, LineEditorCreator())
tableView.itemDelegate().setItemEditorFactory(ief)
with LineEditorCreator defined as follows:
class LineEditCreator(QItemEditorCreatorBase):
def __init__(self):
QItemEditorCreatorBase.__init__(self)
def createWidget(self, parent):
wdgt = QLineEdit(parent)
wdgt.setAutoFillBackground(True)
return wdgt
def valuePropertyName(self):
return "String"
however now I get a Segmentation fault as soon as I try to edit a cell value. Putting a print statement in as the first line in the createWidget statement shows it not ever getting executing - some print statements in the createWidget shows that the Segmentation faults occur even before the first line of createWidget executes (though the __ init __ method completes fine).
Ceppo also said that the behaviour I'm experiencing could be due to a bug (in Qt, PyQt or something else underlying) - I'll be replacing my current Ubuntu 15.10 installation with 16.04 soon so with some luck that will solve the issue entirely.
Upgrading ubuntu 15.10 to 16.04 did indeed fix the problem.
My 16.04 distro has python3-pyqt5 and other qt packages with versions all around 5.5.1 - I did check but didn't think to jot down the versions of those packages in my 15.10 installation before wiping it - but packages.ubuntu.com says 5.4.2 is the current version for 15.10 and that sounds familiar.
So if anyone else with QT 5.4.2 is running into the same thing, upgrading to 5.5.1 might be worth a try - either by upgrading to a newer distro or attempting to find and use a backport of the newer QT version.
Thanks Ceppo93, it was a good guess.

JMSTranslation Cannot parse file

I'm running into a very weird issue. I have 1 file with certain code that is valid only in PHP5.5+ and whenever I run the jmstranslation bundle command line to extract messages I get the error saying that file (on that specific line cannot be parsed). It's very weird because I made sure that the php version I have on my machine is 5.5+ (and everything runs just fine including the phpunit tests).
The exact error I got is
[RuntimeException]
Could not parse "Processor.php": Unexpected token '=' on line 135
[PHPParser_Error]
Unexpected token '=' on line 135
The code that caused the error:
if (!empty($adjustments = $this->createAdjustments($order)))
{
// the empty check above should work in PHP 5.5+
// ...
}
Why do you assign a variable (here $adjustments) in the if test? In some cases it's useful, but in your case is it a typo, instead of the == operator ?
Did you try to perform the same operation in 2 steps?
$adjustments = $this->createAdjustments($order);
if (!empty($adjustments))
{
// the empty check above should work in PHP 5.5+
// ...
}

I cannot include winsock2.h using MinGW

I'm using Qt Creator with MinGW.
I included "windows.h" and compile it, but it failed. Errors are below:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/windows.h:98:0,
from util/IdleDetector.h:8,
from service\PresenceService.cpp:8:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:771:22: error: expected unqualified-id before string constant
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:1034:95: error: expected identifier before string constant
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:1034:95: error: expected ',' or '...' before string constant
I thought that the MinGW path was missing, but that's not the case. How can I fix this?
Is windows.h pulling in winsock.h or winsock2.h? The two are not compatible with each other. winsock2.h is meant to replace winsock.h, and as such re-declares a lot of things that winsock.h already declares. If winsock2.h is included before winsock.h, then winsock2.h silently disables winsock.h and all is fine. But if winsock.h is included before winsock2.h, all kinds of errors can occur.

including Qt headers in DLL

I have a DLL in wich I would like to take a reference to a QObject and manipulate it, without actually creating an interface. So, I included "Qt/qobject.h" and compiled, but the compiler (Visual Studio 2008 pro) gives me syntax errors. It looks like it doesn't recognize the QThread object. How do I use a QObject in my dll? Is this even possible? Do I have to start my program from a Qt app? I'm actually trying to set a system-wide hook and get 3rd application QWidgets to manipulate... Any idea how I can use QObject in my dll?
Here are the errors:
1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
1>Compiling...
1>FTClient.cpp
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
1>FroggerDLL - 6 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
Any help would be greatly appreciated,
Thanks
Dave
What's on line 154? Mine is just the declaration
QThread* thread() const;
but that's 4.5.1 on Linux so it might be different. The first reference to anything involving the token type is on line 204 which is a variable of type Qt::ConnectionType.
BTW. I just tried compiling the following on my system ( in the file incqobj.cpp )
include <QOObject>
QObject myQOject;
with
g++ -I/usr/lib/qt4/include -I/usr/lib/qt4/include/QtCore -c incqobj.cpp
and it compiled fine so it should be as simple as that.
Edit: Since Jesse confirms that it works for him on Windows I'm tempted to say that you've got a non-Qt macro coming in and interfering. One thing you could do is a sanity check on what the compiler is actually seeing by getting VS to only produce the preprocessed source rather than do the compilation.
I haven't used VS in years but I think the option is \E maybe?
[Edit: see the 2nd comment by Jesse, it should be /E] It may also be an explicit option now in the compiler properties which can be set for that source file. Can't remember where it puts the output either so you may need to hunt around for it a bit! If you get that going though you can check to see if the code looks right at the part that would correspond to line 154 in the original QObject header.
Thanks for all the help, solution: I had to include the Qt headers before all my other includes, and it now compiles.
Thanks again!
Try including QThread?
#include <QThread>
Qt uses forward declaration extensively and sometimes you need to include extra headers.
EDIT:
Do you set any defines? Here is what I have for my 2003 Qt commercial (4.3.4) project (executable that links to Qt dlls):
QT_LARGEFILE_SUPPORT
QT_DLL
QT_GUI_LIB
QT_CORE_LIB
QT_THREAD_SUPPORT
QT_NETWORK_LIB

mingw spitting countless warnings about ignoring "dll import" attribute

I'm using mingw32-make to compile a qt project that uses opengl, it compiles correctly and everything, but it spits countless warning messages of the form:
c:/qt3/include/qcolor.h:67: warning: inline function `int qGray(int, int,
int)' declared as dllimport: attribute ignored
For this particular instance, the function declaration is:
Q_EXPORT inline int qGray( int r, int g, int b )// convert R,G,B to gray 0..255
{ return (r*11+g*16+b*5)/32; }
My question is, why is it spitting all these warning? how can I silence them without silencing other legitimate warnings (i.e. warnings that are related directly to my code and could be potential problems)?
More importantly, why is mingw ignoring the dll import attribute in the first place?
I think Qt ought to only define Q_EXPORT (Q_DECL_EXPORT in Qt 4) to be the dllexport/import attribute if one of the following macros is defined, so make sure your makefiles or code that includes Qt headers (which eventually will include qglobal.h) aren't defining any of them: WIN32, _WIN32, __WIN32__, WIN64, _WIN64, __WIN64__. Or you can just define Q_EXPORT to be nothing in your compile (or preprocessor) flags, then Qt should skip defining it.

Resources