Header prototype mistake .. any help?



  • The header was as follows in class

    @class MidiPlayer : public QThread
    {
    Q_OBJECT
    public:
    MidiPlayer(QMidiFile* file, QMidiOut* out)
    { midi_file = file; midi_out = out; }
    //MidiPlayer();

    @

    how can i do it in the c file, i wrote it as follows but it has a prototype mistake

    @
    #include "midiclass.h"

    midiclass::midiclass(QThread *parent) :
    QObject(parent)
    {

    }

    @

    any idea is appreciated ... thanks


  • Moderators

    Your class name is MidiPlayer, not midiclass. So you need to use that:
    @
    #include "midiclass.h"

    MidiPlayer ::MidiPlayer (QMidiFile* file, QMidiOut* out) :
    QThread(someParent)
    {

    }
    @

    You are not passing any parent to the constructor, so you can't assign the parent of the QThread, too. You should correct that.



  • Thank you for your help...I changed the classname to midiclass. if i use the following, i get an error :-> redefinition of midiclass::midiclass

    header
    @

    class midiclass : public QThread
    {
    Q_OBJECT
    public:
    midiclass(QMidiFile* file, QMidiOut* out) { midi_file = file; midi_out = out; }
    //MidiPlayer();

    void play();
    

    private:

    QMidiEvent* midi_file_event;
    QMidiFile* midi_file;
    QMidiOut* midi_out;
    

    };
    @

    cpp file
    @
    midiclass::midiclass (QMidiFile* file, QMidiOut* out) :
    QThread(parent)
    {
    this->play();
    }
    @

    The following code is the code that works, but i want to make it in form of a header to be able to call it from other processes .. I don't know how can i call it from another process in the following format ..

    @

    #include <stdio.h>
    #include <QThread>
    #include <QElapsedTimer>
    #include <QCoreApplication>
    #include <QMidiOut.h>
    #include <QMidiFile.h>

    class MidiPlayer : public QThread
    {
    Q_OBJECT
    public:
    MidiPlayer(QMidiFile* file, QMidiOut* out)
    { midi_file = file; midi_out = out; }
    //MidiPlayer();

    void play();
    

    private:
    QMidiEvent* midi_file_event;
    QMidiFile* midi_file;
    QMidiOut* midi_out;

    protected:
    void run()
    {
    QElapsedTimer t;
    t.start();
    QList<QMidiEvent*>* events = midi_file->events();
    for(int i = 0; i < events->count(); i++)
    {
    midi_file_event = events->at(i);
    if (midi_file_event->type() != QMidiEvent::Meta)
    {
    qint64 event_time = midi_file->timeFromTick(midi_file_event->tick()) * 1000;

                qint32 waitTime = event_time - t.elapsed();
                if(waitTime > 0) {
                    msleep(waitTime);
                }
                handleEvent();
            }
        }
    
        midi_out->disconnect();
    }
    

    private slots:
    void handleEvent()
    {
    if (midi_file_event->type() == QMidiEvent::SysEx)
    { // TODO: sysex
    }
    else
    {
    qint32 message = midi_file_event->message();
    midi_out->sendMsg(message);
    }
    }
    };

    void MidiPlayer::play()
    {
    QString filename = "D:/Activate Software/typing tutor MAC/login/Release/Win/bg.mid";
    QString midiOutName = "";
    QMidiFile* midi_file = new QMidiFile();
    midi_file->load(filename);

    QMidiOut* midi_out = new QMidiOut(&#41;;
    midi_out->connect(midiOutName);
    MidiPlayer* p = new MidiPlayer(midi_file,midi_out);
    p->start();
    

    }
    #include "playsmf.moc"

    @


  • Moderators

    You get the redefinition error, because you have defined the constructor of your class twice:

    in the header file (the stuff between '{' and '}')

    in the source file (midiclass::midiclass)

    You need only one definition of a constructor - either in the header, or in the source file.



  • does this mean i have to write it this way

    @
    midiclass::midiclass () :
    QThread(parent)
    @



  • could you please correct me the code mistake because i can not do it and i gave up ..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.