Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Header prototype mistake .. any help?
Forum Updated to NodeBB v4.3 + New Features

Header prototype mistake .. any help?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #3

        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"

        @

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SherifOmran
            wrote on last edited by
            #5

            does this mean i have to write it this way

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SherifOmran
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved