Skip to content

Language Bindings

You're using Qt with other languages than C++, eh? Post here!
860 Topics 3.4k Posts
  • PySide Installer on Windows

    2
    0 Votes
    2 Posts
    1k Views
    C

    Doesn't actually work with pip and easy_install as suggested "here":http://qt-project.org/wiki/PySide_Binaries_Windows

    And I am still using the old installer for windows. Hope this will be fixed.

  • 0 Votes
    2 Posts
    3k Views
    B

    I think I solved this. I was calling loadUi in the function call. That was not needed because the call to loadUi was already defined in the runoptions class.

    Silly me.

    I am still getting this error;

    bq. Object::connect: No such slot runoptions::accept()
    Object::connect: (sender name: ‘buttonBox’)
    Object::connect: (receiver name: ‘Dialog’)
    Object::connect: No such slot runoptions::reject()
    Object::connect: (sender name: ‘buttonBox’)
    Object::connect: (receiver name: ‘Dialog’)

    The 'runoptions' form contains an OK and Cancel button which do not work. Not sure how to fix that but at least I am making some progress.

    I am not getting the "Designer" error anymore.
    Cheers,

  • PySide, pySerial and threading causes segfault

    1
    0 Votes
    1 Posts
    3k Views
    No one has replied
  • Accessing objects into another class

    6
    0 Votes
    6 Posts
    2k Views
    SGaistS

    Just setup your database and open it once e.g. in your main function. There's no need to close/open it every time you want to access it unless you have a very good reason

  • Integrating Qt as debug tool for server app

    4
    0 Votes
    4 Posts
    1k Views
    A

    moderator hat on: Using foul language is not acceptable here. Please practice patience for getting replies on your queries. If you need immediate answers, get paid support from one of the many vendors offering that.

    On your actual query: I think you're having a problem integrating event loops. I would not recommend trying to integrate a Qt UI into a service. Instead, I'd set up the design in a way that your service can communicate with an application via a simple protocol, and you keep the GUI as a separate process from the actual service. A local socket will do, but a network port just as well. DBUS may be good option for you as well.

  • [PySide] List model from PySide to QML

    2
    0 Votes
    2 Posts
    2k Views
    K

    Still seeking a reply to this.

  • Exit QThread Cleanly

    2
    0 Votes
    2 Posts
    2k Views
    jazzycamelJ

    Before I answer your question I will first say that, despite examples given in the docs, it is generally considered a bad idea to subclass QThread and instead create a worker object that is moved into a thread. To stop a QThread you need to call quit() and, if that fails, terminate(). The issue here is that you're running a blocking method and no event loop so these methods will not work on there own. What you therefore need is a flag that is checked on every iteration of the forever loop and set by a signal/slot call from your main thread when the GUI exits. The following files form a minimal working example:

    widget.h
    @
    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>

    class QThread;

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    private:
    QThread *thread;

    signals:
    void stopThread();

    public slots:
    void start();
    void tick();
    };

    #endif // WIDGET_H
    @

    widget.cpp
    @
    #include "widget.h"
    #include "threaded.h"

    #include <QVBoxLayout>
    #include <QPushButton>
    #include <QThread>
    #include <QDebug>

    Widget::Widget(QWidget *parent) :
    QWidget(parent)
    {
    QVBoxLayout *l=new QVBoxLayout(this);

    QPushButton *startButton=new QPushButton("Start", this); connect(startButton, SIGNAL(clicked()), this, SLOT(start())); l->addWidget(startButton);

    }

    Widget::~Widget()
    {
    if(thread->isRunning()){
    emit stopThread();
    thread->quit();
    if(!thread->wait(5000)){
    thread->terminate();
    if(!thread->wait(5000)) qDebug() << "Failed to terminate!";
    }
    }
    }

    void Widget::start(){
    thread=new QThread();
    Threaded *threaded=new Threaded();
    connect(this, SIGNAL(stopThread()), threaded, SLOT(stop()));
    connect(threaded, SIGNAL(tick()), this, SLOT(tick()));
    connect(thread, SIGNAL(started()), threaded, SLOT(work()));
    threaded->moveToThread(thread);
    thread->start();
    }

    void Widget::tick(){
    qDebug() << "tick";
    }
    @

    threaded.h
    @
    #ifndef THREADED_H
    #define THREADED_H

    #include <QObject>

    class Threaded : public QObject
    {
    Q_OBJECT
    public:
    explicit Threaded(QObject *parent = 0);

    private:
    bool mStop;

    signals:
    void tick();

    public slots:
    void work();
    void stop();
    };

    #endif // THREADED_H
    @

    threaded.cpp
    @
    #include "threaded.h"

    #include <QMutex>
    #include <QWaitCondition>
    #include <QCoreApplication>

    Threaded::Threaded(QObject *parent) :
    QObject(parent), mStop(false)
    {}

    void Threaded::work(){
    QMutex dummy;
    QWaitCondition waitCondition;

    forever{ dummy.lock(); waitCondition.wait(&dummy, 1000); emit tick(); dummy.unlock(); QCoreApplication::processEvents(); if(mStop) break; }

    }

    void Threaded::stop(){
    mStop=true;
    }
    @

    main.cpp
    @
    #include <QtGui/QApplication>
    #include "widget.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec&#40;&#41;;

    }
    @

    Hope this helps ;o)

  • 0 Votes
    1 Posts
    2k Views
    No one has replied
  • 0 Votes
    7 Posts
    6k Views
    J

    Thank you so much! I love your last example too! With that teh post it's complete, thanks for eveything :)

  • Segfault after signal emit

    4
    0 Votes
    4 Posts
    3k Views
    A

    It would be good if someone more knowledgeable than me could comment on my first attempt that ends in a segfault. is this a bug in pyside or is it not intended to be used like that?

  • 0 Votes
    4 Posts
    4k Views
    W

    Thank you guys for your answers. I use Windows 7 with Python 2.7.6 and Pyside as Qt-Python bindings. But i also like to test it on a Debian or openSUSE Linux. I read in the API guide to use QFileSystemModel instead of deprecated QDirModel. If i use

    @self.dirModel = QDirModel()
    self.sourceTreeView.setModel(self.dirModel)@

    in my code, the TreeView gets automatic updated when i insert/remove my USB-Stick. I thought i can have that behavior also with QFileSystemModel() in some configuration.

    So what is the best way to detect an insert/remove of an USB-Stick on Windows and Linux using Pyside Qt bindings?

  • [PyQt] Custom Scrollbar design {SOLVED}

    5
    0 Votes
    5 Posts
    18k Views
    jazzycamelJ

    Try the following:

    @
    import sip
    sip.setapi('QVariant',2)
    sip.setapi('QString',2)

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *

    class ScrollBar(QScrollBar):
    def init(self, parent=None, **kwargs):
    QScrollBar.init(self, parent, **kwargs)

    self.setStyleSheet(""" QScrollBar:horizontal { border: none; background: none; height: 26px; margin: 0px 26px 0 26px; } QScrollBar::handle:horizontal { background: lightgray; min-width: 26px; } QScrollBar::add-line:horizontal { background: none; width: 26px; subcontrol-position: right; subcontrol-origin: margin; } QScrollBar::sub-line:horizontal { background: none; width: 26px; subcontrol-position: top left; subcontrol-origin: margin; position: absolute; } QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal { width: 26px; height: 26px; background: none; image: url('./glass.png'); } QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { background: none; } /* VERTICAL */ QScrollBar:vertical { border: none; background: none; width: 26px; margin: 26px 0 26px 0; } QScrollBar::handle:vertical { background: lightgray; min-height: 26px; } QScrollBar::add-line:vertical { background: none; height: 26px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::sub-line:vertical { background: none; height: 26px; subcontrol-position: top left; subcontrol-origin: margin; position: absolute; } QScrollBar:up-arrow:vertical, QScrollBar::down-arrow:vertical { width: 26px; height: 26px; background: none; image: url('./glass.png'); } QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { background: none; } """)

    class Widget(QWidget):
    def init(self, parent=None, **kwargs):
    QWidget.init(self, parent, **kwargs)

    self.setWindowTitle("Custom Scroll Bar Example") l=QVBoxLayout(self) self._scrollArea=QScrollArea(self) self._scrollArea.setVerticalScrollBar(ScrollBar(self)) self._scrollArea.setHorizontalScrollBar(ScrollBar(self)) w=QWidget(self) ll=QGridLayout(w) for i in xrange(20): for j in xrange(10): ll.addWidget( QPushButton( "Button ({0},{1})".format(i,j), self ), i, j ) self._scrollArea.setWidget(w) l.addWidget(self._scrollArea) self.resize(250,400)

    if name=="main":
    from sys import argv, exit

    a=QApplication(argv) w=Widget() w.show() w.raise_() exit(a.exec_())

    @

    It should look something like:

    !http://s24.postimg.org/rhcr4uzs5/Screen_Shot_2014_05_06_at_12_21_29.png(Custom Scroll Bar Example Screenshot)!

    You'll just have to find an image to substitute for my 'glass.png'.

    Hope this helps ;o)

  • 0 Votes
    6 Posts
    2k Views
    EddyE

    My pleasure!

    Happy coding

  • 0 Votes
    3 Posts
    1k Views
    SGaistS

    Hi,

    To add to JKSH, the same principles applies to Python. This way you keep your code clean by having your MainWindow related code inside the class. So It's not your application main function that is responsible for the MainWindow setup. It will also make your code easily maintainable.

  • 0 Votes
    2 Posts
    1k Views
    P

    I cracked it myself anyway.

    I am not sure what exactly happend, I deleted the system generated file when debug (file name : Qt_PATH_System_Debug) and re compiled in debug mode it works all fine

  • 0 Votes
    3 Posts
    5k Views
    SGaistS

    Hi,

    To add to JvdGlind, toAscii and its fellow conversion function returns a temporary QByteArray so calling

    @char *foo = myQString.toAscii().data();
    doSomethingWithFoo(foo);@

    Will lead to undefined behavior.

    The correct way would be
    @
    QByteArray myAsciiByteArray = myQString.toAscii();
    char *foo = myAsciiByteArray.data();
    doSomethingWithFoo(foo);@

  • 0 Votes
    3 Posts
    7k Views
    D

    Can you show me an example of how to do this? I can't understand this link.

    thanks!

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    You should anyway try to create a minimal application. That way you can determine if it's a Qt bug or a PySide thing.

    Also, another thing to try is a more recent version of Qt like 4.8.6 is around the corner.

  • 0 Votes
    2 Posts
    1k Views
    T

    Issue resolved. I posted a "patch":":http://lists.qt-project.org/pipermail/pyside/2014-April/002013.html on the pyside mailing list.

  • Direct stdio to combo box

    4
    0 Votes
    4 Posts
    1k Views
    jazzycamelJ

    Glad it worked. Can you mark the thread as [solved] if thats the case ;o)