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. [SOLVED] QTest example doesnt work
Forum Update on Monday, May 27th 2025

[SOLVED] QTest example doesnt work

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.7k Views
  • 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.
  • A Offline
    A Offline
    Aram
    wrote on last edited by Aram
    #1

    Hi all,
    I'm trying to follow QTest example here to make a unit test but it gives me this errors

    /home/aram/MEGA/proj/scratch/test/Qt_Test_Tutorial/tut_1/main.cpp:6: error: 
    undefined reference to `vtable for TestQString'
    

    My code is the same as it is in the example.
    I'm using Qt development environment from my distribution (opensuse leap 42.1)
    Thanks.

    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      do you have Q_OBJECT
      in your class ?
      Try to delete the build folder.
      Then run qmake
      then rebuild all

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Aram
        wrote on last edited by
        #3

        of course i have... as i said, it just a copy

        mrjjM 1 Reply Last reply
        0
        • A Aram

          of course i have... as i said, it just a copy

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Aram
          ok
          also the
          #include "testqstring.moc"
          with the correct name ?
          #include "main.moc"
          (must match the file name)
          This will make the moc.exe tool run on the CPP file. Normally this
          tool only runs on .h files but Test unit are special and the include makes sure
          moc.ex is run on the file.
          The reason I ask is that the eror you get is very like what you get when moc.exe not been run on file.

          A 1 Reply Last reply
          0
          • mrjjM mrjj

            @Aram
            ok
            also the
            #include "testqstring.moc"
            with the correct name ?
            #include "main.moc"
            (must match the file name)
            This will make the moc.exe tool run on the CPP file. Normally this
            tool only runs on .h files but Test unit are special and the include makes sure
            moc.ex is run on the file.
            The reason I ask is that the eror you get is very like what you get when moc.exe not been run on file.

            A Offline
            A Offline
            Aram
            wrote on last edited by
            #5

            @mrjj yes i had those things,,, i solved the problem by removing additional config lines (that qt_creator adds when you create a project) from *.pro file and left it only with

            QT += core testlib
            SOURCES += testfile.cpp
            

            and now it works...

            mrjjM 1 Reply Last reply
            2
            • A Aram

              @mrjj yes i had those things,,, i solved the problem by removing additional config lines (that qt_creator adds when you create a project) from *.pro file and left it only with

              QT += core testlib
              SOURCES += testfile.cpp
              

              and now it works...

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Aram
              Ok. thanks for posting solution.

              1 Reply Last reply
              1

              • Login

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