Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, October 19, 2011

Qt: Undefined reference to vtable


For the past few weeks I have been evaluating various tool-kits for developing glossy user interfaces that you would typically see on a smartphone these days. It had been to toss up between Inflexion from Mentor Graphics or Qt from Nokia. Obviously I have fallen on to the side of Qt for the option of using the SDK under LGPL.

So I have been climbing the learning curve, created a very slick user interface, putting my GIMP skills to the test, while putting it together very quickly using QtQuick. The next step was to link some C++ functions to the interface. Couldn't find much information, that was correct, that could help me link a C++ application to a QML file.

For a long time I was getting an error in Qt creator for an Undefined reference to vtable, what this means? I am unsure, I am know it is an error linked to the macro Q_OBJECT and the linker, I found that if I include the file main.moc after I have declared the classes then it ran without issue. Check out what Qt have to say about it here.

Using a combination of a few resources I'm posting my findings to hopefully help other Qt newbies in getting up and running quickly.

main.cpp (remember the headers!)
class MyClass : public QObject
{
    Q_OBJECT
public slots:
    void cppMethod(const QString &msg){
        qDebug() << "Called the C++ slot with" << msg;
    }
};
#include "main.moc"
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QDeclarativeView view;
    MyClass myClass;
    view.rootContext()->setContextProperty("myObject",&myClass);
    view.setSource(QUrl::fromLocalFile("qml/linkTest/main.qml"));
    view.show();
    return app.exec();
}
Extract from main.qml
MouseArea {
      id: mouse_area
      x: 4
      y: 9
      width: 442
      height: 91
      smooth: true

      onClicked: {
          menuView.currentIndex = index+5
          myObject.cppMethod("Hello from QML")
      }
}
 

Wednesday, September 21, 2011

GPIO Interrupts on the i.MX53


So I had been scouring the web for some information on how to use the GPIO pins as kernel interrupts. There is plenty of reference material on how to use sysfs interface to poll the pins manually but I couldn't figure out the interrupts, with some perserverance and  some digging through the source tree I came up with this.

Bear in mind my platform is the imx53 based DIMM-MX53 from Emtrion but the theory should still apply across the board including the IMXQSB.

static irqreturn_t button_interrupt(int irq, unsigned long data)
{
printk(KERN_INFO "Hello World\n");
tasklet_schedule(&my_tasklet);
return IRQ_HANDLED;
}

static int __init hello_start(void)
{
int ret;
 
printk(KERN_INFO "Loaded hello module....\n");
ret = request_irq(gpio_to_irq(42), button_interrupt,
IRQF_DISABLED | IRQF_TRIGGER_FALLING,
"hello", NULL);
if(ret){
printk(KERN_ERR "Failed to request IRQ\n");
return ret;
}
return 0;
}
The macro gpio_to_irq(x) changes the GPIO address to an IRQ, in my case I'm using the second 32 bit GPIO port and bit 10 (GPIO2-10). It is also worth noting that it is probably bad practice to request the IRQ during the initialisation but rather when you want to use the device, this way you will not hog any system resource.

This should be enough to get you going, enjoy.