Using QTextToSpeech causing multiple definitions errors



  • I was trying to follow the example code for QTextToSpeech from https://doc.qt.io/qt-5.10/qtspeech-hello-speak-example.html
    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
    {
        public:
            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);
    
    
        protected:
    
    
        private:
            QTextToSpeech *example_speech;
            QVector<QVoice> vector_voices;
    
    };
    
    Example::Example()
    {
    
    }

  • Qt Champions 2017

    Hi
    The implementation IS in the cpp file ?
    Example::Example()
    {

    }
    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!


  • Qt Champions 2017

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


Log in to reply
 

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