Results 1 to 4 of 4

Thread: Joystick Reader

  1. #1
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Joystick Reader

    I wrote the following code,and getting error::
    1. no void MainWindow::joyConnect() member function in class MainWindow.
    2. no void MainWindow::updateForm() member function in class MainWindow.
    3. btnConnect not declared in scope.

    >>>>>>>>>>>>>>>>>>>>>
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QTimer>


    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QTimer* timer = new QTimer(this);
    new joystick = new Joystick();
    connect(timer, SIGNAL(timeout()), this, SLOT(updateForm()));
    connect(btnConnect,SIGNAL(clicked()),this, SLOT(joyConnect()));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::joyConnect()
    {
    if(joystick->init(joyAccess->text().toAscii()) > -1)
    {
    ui->btnConnect->setText("Connected");
    timer->start();
    }

    }
    void MainWindow::updateForm()
    {
    ui->lcd1->display(joystick->getAxis(0));
    ui->lcd2->display(joystick->getAxis(1));
    ui->lcd3->display(joystick->getAxis(2));
    ui->lcd4->display(joystick->getAxis(3));


    if(joystick->getButton(0) > 0)
    ui->label_1->setText("UP");
    else
    ui->label_1->setText(" Axis1");

    if(joystick->getButton(1) > 0)
    ui->label_2->setText("Down");
    else
    ui->label_2->setText(" Axis2");


    if(joystick->getButton(2) > 0)
    ui->label_3->setText("UP");
    else
    ui->label_3->setText(" Axis3");


    if(joystick->getButton(3) > 0)
    ui->label_4->setText("UP");
    else
    ui->label_4->setText(" Axis4");

    }

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Joystick Reader

    Should be:
    Qt Code:
    1. connect( ui->btnConnect, ... )
    To copy to clipboard, switch view to plain text mode 
    ( please use [CODE] tags, its easier to read the code )
    ---
    edit: post the header also

  3. The following user says thank you to stampede for this useful post:

    Arpitgarg (6th March 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Joystick Reader

    I sorted out the previous error but having following difficulties:
    1. joystick.h: no such file or dirrctory
    2. C++ forbids declaration of 'joystick' with no type



    [HEADER]
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QTimer>
    #include <joystick.h>


    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QTimer *timer;
    Joystick *joystick;

    private:
    Ui::MainWindow *ui;
    void updateForm();
    void joyConnect();
    };

    #endif


    [CODE]
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QTimer>


    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QTimer* timer = new QTimer(this);
    new joystick = new Joystick();
    connect(timer, SIGNAL(timeout()), this, SLOT(updateForm()));
    connect(btnConnect,SIGNAL(clicked()),this, SLOT(joyConnect()));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::joyConnect()
    {
    if(joystick->init(joyAccess->text().toAscii()) > -1)
    {
    ui->btnConnect->setText("Connected");
    timer->start();
    }

    }
    void MainWindow::updateForm()
    {
    ui->lcd1->display(joystick->getAxis(0));
    ui->lcd2->display(joystick->getAxis(1));
    ui->lcd3->display(joystick->getAxis(2));
    ui->lcd4->display(joystick->getAxis(3));


    if(joystick->getButton(0) > 0)
    ui->label_1->setText("UP");
    else
    ui->label_1->setText(" Axis1");

    if(joystick->getButton(1) > 0)
    ui->label_2->setText("Down");
    else
    ui->label_2->setText(" Axis2");


    if(joystick->getButton(2) > 0)
    ui->label_3->setText("UP");
    else
    ui->label_3->setText(" Axis3");


    if(joystick->getButton(3) > 0)
    ui->label_4->setText("UP");
    else
    ui->label_4->setText(" Axis4");

    }

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Joystick Reader

    1. joystick.h: no such file or dirrctory
    Where is this file located ? You should add INCLUDEPATH += dir ( where dir contains "joystick.h" ) to your .pro file
    C++ forbids declaration of 'joystick' with no type
    I don't know where does this one came from, but I assume this line:
    Qt Code:
    1. new joystick = new Joystick();
    To copy to clipboard, switch view to plain text mode 
    should be
    Qt Code:
    1. this->joystick = new Joystick();
    To copy to clipboard, switch view to plain text mode 
    But this is related to C++ in general - are you familiar with C++ ?

Similar Threads

  1. Emulating Joystick Input in Linux ( C++ )
    By invisible_uli in forum General Programming
    Replies: 6
    Last Post: 5th January 2012, 07:01
  2. RSS Reader
    By numbat in forum Qt-based Software
    Replies: 2
    Last Post: 6th April 2011, 10:42
  3. Help with Binary reader in qt ???
    By rajji_saini in forum Qt Programming
    Replies: 7
    Last Post: 20th September 2010, 05:34
  4. xml reader
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th January 2008, 18:37
  5. Qt + Barcode Reader
    By sunil.thaha in forum General Discussion
    Replies: 12
    Last Post: 13th November 2007, 12:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.