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. Multiple definition WTF
Forum Updated to NodeBB v4.3 + New Features

Multiple definition WTF

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.7k 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.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by Kofr
    #1

    I created 2 functions for convertions. I put them into the globally avaliable fheader file. Which has protection of multiple includes. But I get 47 errors D:\dev\app\DataTypes\enums.h:18: ошибка: multiple definition of (QByteArray)' (24 for each function). The problems are found in MOC files D:\dev\build-app-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\moc_usergroupscontroller.o:-1: In function ZN12QMapNodeBase25callDestructorIfNecessaryIyEEN9QtPrivate9QEnableIfIXntsr9QTypeInfoIT_E9isComplexEvE4TypeERS4_':`
    What is wrong??

    /// converts quintptr to QByteArray object
    QByteArray convert(quintptr t_arg) {
        QByteArray converted;
        QDataStream stream(&converted, QIODevice::WriteOnly);
        stream << t_arg;
        return converted;
    }
    /// converts QByteArray to quintptr object
    quintptr convert(QByteArray t_arg) {
        //QByteArray AvailableId = getlastMaxid();
        quintptr converted;
        QDataStream stream(&t_arg, QIODevice::ReadOnly);
        stream >> converted;
        return converted;
    }
    
    K 1 Reply Last reply
    0
    • M Offline
      M Offline
      mtrch
      wrote on last edited by
      #2

      @Kofr said in Multiple definition WTF:

      I put them into the globally avaliable fheader file.

      You should put function bodies in .cpp file. Header file must hold only forward declarations without function body:

      QByteArray convert(quintptr t_arg);
      quintptr convert(QByteArray t_arg);
      
      K 1 Reply Last reply
      2
      • K Kofr

        I created 2 functions for convertions. I put them into the globally avaliable fheader file. Which has protection of multiple includes. But I get 47 errors D:\dev\app\DataTypes\enums.h:18: ошибка: multiple definition of (QByteArray)' (24 for each function). The problems are found in MOC files D:\dev\build-app-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\moc_usergroupscontroller.o:-1: In function ZN12QMapNodeBase25callDestructorIfNecessaryIyEEN9QtPrivate9QEnableIfIXntsr9QTypeInfoIT_E9isComplexEvE4TypeERS4_':`
        What is wrong??

        /// converts quintptr to QByteArray object
        QByteArray convert(quintptr t_arg) {
            QByteArray converted;
            QDataStream stream(&converted, QIODevice::WriteOnly);
            stream << t_arg;
            return converted;
        }
        /// converts QByteArray to quintptr object
        quintptr convert(QByteArray t_arg) {
            //QByteArray AvailableId = getlastMaxid();
            quintptr converted;
            QDataStream stream(&t_arg, QIODevice::ReadOnly);
            stream >> converted;
            return converted;
        }
        
        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @Kofr

        The protection of multiple includes does work only for recursive inclusion.
        E.g. main.cpp includes header1.h includes header2.h includes header1.h
        The last include will not happen.

        You probably have
        main.cpp includes header1.h includes header2.h
        inpHeader1.cpp includes header1.h

        There it will be includes twice.

        You can do

        /// converts quintptr to QByteArray object
        inline QByteArray convert(quintptr t_arg) {
            QByteArray converted;
            QDataStream stream(&converted, QIODevice::WriteOnly);
            stream << t_arg;
            return converted;
        }
        /// converts QByteArray to quintptr object
        inline quintptr convert(QByteArray t_arg) {
            //QByteArray AvailableId = getlastMaxid();
            quintptr converted;
            QDataStream stream(&t_arg, QIODevice::ReadOnly);
            stream >> converted;
            return converted;
        }
        

        There the functions will be generated where required. It is matter of taste if you really like to do it this way or rather setup a cpp-file and do it the standard way.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        3
        • M mtrch

          @Kofr said in Multiple definition WTF:

          I put them into the globally avaliable fheader file.

          You should put function bodies in .cpp file. Header file must hold only forward declarations without function body:

          QByteArray convert(quintptr t_arg);
          quintptr convert(QByteArray t_arg);
          
          K Offline
          K Offline
          Kofr
          wrote on last edited by
          #4
          This post is deleted!
          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