Using QTextToSpeech causing multiple definitions errors

  • I was trying to follow the example code for QTextToSpeech from
    I modified it slightly but not in a way that should've broken anything. I get the following error when running the below code.

    Multiple definition of `Example::Example()`
    In function `QTypedArrayData<QVoice>::sharednull()`:

    This error occurs five times and references the same thing. Can anyone explain what's happening?

    #include "QTextToSpeech"
    class Example
            void speak(QString &words);
            void stop();
            void set_rate(int r);
            void set_pitch(int p);
            void set_volume(int v);
            void state_changed(QTextToSpeech::State state);
            void engine_selected(int index);
            void language_selected(int lang);
            void voice_selected(int index);
            void locale_changed(const QLocale &locale);
            QTextToSpeech *example_speech;
            QVector<QVoice> vector_voices;

  • Lifetime Qt Champion

    The implementation IS in the cpp file ?

    and not under class in .h as that would give multiple defines errors

  • Sorry, I didn't realize that I didn't paste everything. Yes, it was in there, turns out for some reason there were multiple inclusions of the header and cpp in the .pro, once I removed those it took the errors away. I think it occurred when I modified it outside of the editor. I'm going to close this out!

  • Lifetime Qt Champion

    Ah, yes its a classic. If you use the New Class dialog and overwrite files
    this can easy happen.

Log in to reply