Menu

generator: Unexplained Warnings and results

2019-02-13
2019-04-05
  • Allen C Kempe

    Allen C Kempe - 2019-02-13

    When using the latest version of PythonQt downloaded using SVN, I have encountered several strange or unexplained results.

    • when a package name is specified as 'test' in the typesystem file, the generated package names are outout as 'Test' but the folder, .cpp files, and .h files generated all use 'test' in their names.
    • generated PythonQtShell headers are created with a semicolon following the closing brace, e.g "{};" While not a major problem, it causes the lines to be highlighed as possibly in error by the Qt Creator editor.
    • I'm getting warning errors stating " WARNING #endif without #if" however no file name is shown. I tried modifying the code to display the current file name but could not determine that there were any unmatched #if/#endif statments in the file.
    • Occasionally, generated wrapper functions are generated with the wrong return class type. Instead of "QList<int> function { returns QList<int> a;</int></int>} " it generates * "ClassA PythonQtWrapperClassA::function { returns QList<int> a;} " *where ClassA is the C++ classname. The only contributing factor I can attribute to this is that the original C++ header was defined using the QT_DEPRECATED property. </int>
    • Sometimes C++ functions returning a QStringList are generated with QStringList<qstring> resulting in a compile error about QStringLIst not being a template. </qstring>
    • If no header file is given in the wrapper header file, or if there is not an include path specified for the file, classes will not be generated. But no warning or error is displayed.
    • if the wrapper header file contains an invalid #include filename, no error or warning is displayed.
    • Another warning that I get that doesn't seem to be causing any problem is when the generator sys there is an unknown baseclass for 'xxxx : QObject' This also occurs for Qt API classes like QLayour, QLabel, etc.

    It seems like a nice option would be to ignore functions that are deprecated if they are defined with QT_DEPRECATED (or any other valid way to declare deprecated functions) property. Although the 'rejection' tag can be used, it could be troublesome to have to specify each deprecated functions individutally.

     
  • Florian Link

    Florian Link - 2019-02-14

    Thanks for reporting, could you say which Qt version you are using?

    I am not actively working on PythonQt right now, so maybe you can have a look by yourself.

     
  • Allen C Kempe

    Allen C Kempe - 2019-02-15

    I am using Qt version 5.7

    Since I reported this, I have come across a few other anomalies.

    I have a subclass of QMainWindow. called JFrame. In my script, I got an error when I tried to 'f.setVisible(True)' that JFrame has no method called 'setVisible'.  Since QMainWindow.set visible is virtual, it should have worked. What I did to solve this problem was to add a function, 'setVisible' in QFrame that just called QMainWindow::setVisible. 
    I cannot seem to get signals and slots to do anything. I don't get an error but the class defined to handle the signal never gets called. 
    In researching the Signal/slot problem, I tried running the script posted in https://sourceforge.net/p/pythonqt/discussion/631393/thread/bbc98b8f/?limit=25#1a5c after emiting a signal but get this error:
    
    Traceback (most recent call last):
    
      File "/home/allen/.jmri/jython/signals.pyq", line 3, in <module>
    
    class C(QtCore.QObject):
    
    AttributeError
    
    :
    
    'module' object has no attribute 'QObject'
    
     

    Last edit: Allen C Kempe 2019-02-16
  • Allen C Kempe

    Allen C Kempe - 2019-02-16

    I continue to work on the problem of getting connect to work. I did discover one "oops' situation in that my generator script was passing an invalid path for an 'Export QTDIR= ... statement. After correcting the path and rerunning generator, I now see that the Warning messages about QObject being an invalid baseclass have disappeared. However I am still getting warning messages about Qt classes like QMainWindow and QMenu being invalid baseclasses. and the script from https://sourceforge.net/p/pythonqt/discussion/631393/thread/bbc98b8f/?limit=25#1a5c still produces the error 'module' object has no attribute 'QObject'

     
  • Allen C Kempe

    Allen C Kempe - 2019-02-16

    In generator source file main.h, there is a check to see whether the QTDIR environment variable exists and a message is output to qWarning. It should also be output to stdout. Also, there is no check to verify that the directory specified exists.

    Further down, I found that "/QtWidgets" needs to be added to the list of includes in order to find QtClasses like QMainWindow. This eliminates the baseclass not found warnings. I'm wonderign whether the INCLUDES paths should also be verified that they exist?

     
  • Allen C Kempe

    Allen C Kempe - 2019-02-26

    I'm still working on getting connect to work. My problem I believe was because I was trying to use QSignalMapper which doesn't work.

    from PythonQt import *
    from PythonQt.QtGui import QPushButton
    from PythonQt.QtCore import QSignalMapper
    from PythonQt.QtGui import QMainWindow
    from PythonQt.QtGui import QHBoxLayout
    from PythonQt.QtGui import QWidget
    
    list = ["A", "B", "C","D"]
    
    f = QMainWindow()
    f.setWindowTitle("QSignal Mapper Test")
    cw = QWidget();
    centralWidgetLayout = QHBoxLayout()
    cw.setLayout(centralWidgetLayout)
    f.setCentralWidget(cw)
    
    # define action routine for button click
    def whenMyButtonClicked(name) :
        print name
    
    def anyButtonClicked() :
        print 'a button was clicked'
    
    # Now loop to create buttons.
    print (list)
    mapper = QSignalMapper()
    for string in list :
        # create a button for this panel
        b = QtGui.QPushButton(string)
        mapper.setMapping(b, string)
        b.connect('clicked(bool)', mapper.map())
        b.connect('clicked()', anyButtonClicked)
        centralWidgetLayout.addWidget(b)
    mapper.connect('mapped(QString)', whenMyButtonClicked)
    
    # show the control panel frame
    f.adjustSize()
    f.setVisible(True)
    

    This produces this output when one of the buttons is clicked.
    ['A', 'B', 'C', 'D']
    TypeError: 'NoneType' object is not callable
    a button was clicked


    The Qt documentation says that QSignalMapper is obsolete but the only thing I can find is to use Lamda fucntions which I suppose don't ake sense to Python or the sender() function to get a pointer to the Pushbutton but sender apeears to be a method of QObject which PythonQt doesn't support. Anybody got an idea on how to get QSignalMapper working?

     
  • Allen C Kempe

    Allen C Kempe - 2019-03-01

    Here are some changes I am suggesting:

    Index: generator/main.h
    ===================================================================
    --- generator/main.h    (revision 502)
    +++ generator/main.h    (working copy)
    @@ -105,6 +105,12 @@
                 std::cout << "-------------------------------------------------------------" << std::endl;
                 std::cout << "Using QT at: " << qtdir.toLocal8Bit().constData() << std::endl;
                 std::cout << "-------------------------------------------------------------" << std::endl;
    +            QDir dir(qtdir);
    +            if(!dir.exists())
    +            {
    +             qWarning("QTDIR environment variable does not exist. This may cause problems with finding the necessary include files.");
    +             std::cout <<  "WARNING! QTDIR environment variable does not exist. This may cause problems with finding the necessary include files.";
    +            }
                 qtdir += "/include";
                 includes << (qtdir + "/QtXml");
                 includes << (qtdir + "/QtNetwork");
    @@ -111,6 +117,7 @@
                 includes << (qtdir + "/QtCore");
                 includes << (qtdir + "/QtGui");
                 includes << (qtdir + "/QtOpenGL");
    +            includes << (qtdir + "/QtWidgets");
                 includes << qtdir;
             }
             foreach (QString include, includes) {
    Index: generator/shellheadergenerator.cpp
    ===================================================================
    --- generator/shellheadergenerator.cpp  (revision 502)
    +++ generator/shellheadergenerator.cpp  (working copy)
    @@ -152,7 +152,8 @@
           }
           s << "),_wrapper(NULL) {";
           writeInjectedCode(s, meta_class, TypeSystem::PyInheritShellConstructorCode, true);
    -      s << "};" << endl;
    +      //s << "};" << endl;
    +      s << "}" << endl;  // ACK
         }
         s << endl;
         s << "   ~" << shellClassName(meta_class) << "();" << endl;
    
     
  • Tonka

    Tonka - 2019-04-02

    Hey Allen C Kempe,

    I have the same troubles as you mentioned above. Does your last patch suggestion fix some of the above problems like #endif without #if or something like that?

    Greetings
    Tonka

     
  • Allen C Kempe

    Allen C Kempe - 2019-04-02

    I don't believe that the "#endif without #if" problems are appearing because of a real poblem in the input header files but a bug in the PythonQT parser. It may be an indication of some classes not being processed properly. I sort of got sidetracked on other issues and haven't wlooked into any of these issues.

    At the present time, the failure od QSignalMapper as I previously posted about is my biggest concern. My next item of interest is figuring out how to ignore methods marked QT_DEPRECATED.

    Of the two fixes that I posted, one is merely cosmetic, eliminating the generation of an unnecessary ";" on a generated code. The other is to include QWidgets in the include path for QT classes.

    I'e also identified some other things that should be checked, like whether supplied include paths are valid.

     
  • Tonka

    Tonka - 2019-04-02

    I also think that the endif warning is from an pythonqt parser bug. The strange thing is that i get it only when i add additional include directories. The parser sometimes does not see classes, but they are listed in the preprocess file.

    yeah, there are some weird bugs which need some checks.

    Do you use pythonqt only for qt stuff or do you use it for your own code as well (as i do)?

     
  • Allen C Kempe

    Allen C Kempe - 2019-04-03

    I only got involved with PythonQt because I wanted to add scripting capabilities to a QT program.

     
  • Tonka

    Tonka - 2019-04-03

    Me too. I already make a big part of our application scriptable, but the bugs that you mentioned produce a lot of trouble.

    Maybe we can cooperate to fix he bugs.

     
  • Allen C Kempe

    Allen C Kempe - 2019-04-03

    In the next couple of days, I should be able to take a look at some of the problems. What if I setup a repository on github for my changes? That should make it easier to shae any changes we make.

     
  • Tonka

    Tonka - 2019-04-03

    repo on github would be nice. makes it much easier to cooperate.

     
  • Allen C Kempe

    Allen C Kempe - 2019-04-05

    I'm not having a lot of luck yet. I thought that I could add some code to check for QT_DEPRECATED on a function but it's not getting called. It seems that there is a pre-processor that is removing the QT_DEPRECATED token from the source. It looks like the prepocessor code is QT code that I can't see so I've been unable to see how it's doing this.

     
    • Florian Link

      Florian Link - 2019-04-05

      Look in the preprocessor code pr the master include, I guess one of them is
      defining it... or you have to add a define that defines it to itself, so
      that the preprocessor keeps it.

      On Fri 5. Apr 2019 at 19:37, Allen C Kempe allenck@users.sourceforge.net
      wrote:

      I'm not having a lot of luck yet. I thought that I could add some code to
      check for QT_DEPRECATED on a function but it's not getting called. It seems
      that there is a pre-processor that is removing the QT_DEPRECATED token from
      the source. It looks like the prepocessor code is QT code that I can't see
      so I've been unable to see how it's doing this.


      generator: Unexplained Warnings and results


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/pythonqt/discussion/631392/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       
  • Allen C Kempe

    Allen C Kempe - 2019-04-05

    Florian, glad to see you are keeping a watch on things. I tried adding this line to the pp-qt-configuration file but it doesn't seem to have any affect.

    #define QT_DEPRECATED QT_DEPRECATED
    

    I would think that I should be able to set breakpoints in preprocessor.cpp but they never get called.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.