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] QXcbConnection: Could not connect to display [Qt] [Jenkins]
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QXcbConnection: Could not connect to display [Qt] [Jenkins]

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

    I’m having some problems implementing a simple GuiTest (that uses QTestLib) in Jenkins. In a terminal I can execute the following command:

    @./tst_testgui -xunitxml > testresult.xml@

    This command generates the following .xml file:

    @
    <?xml version="1.0" encoding="UTF-8" ?>
    <testsuite errors="0" failures="0" tests="3" name="TestGui">
    <properties>
    <property value="5.0.2" name="QTestVersion"/>
    <property value="5.0.2" name="QtVersion"/>
    </properties>
    <testcase result="pass" name="initTestCase"/>
    <testcase result="pass" name="testGui"/>
    <testcase result="pass" name="cleanupTestCase"/>
    <system-err/>
    </testsuite>@

    In Jenkins I’m trying to do the same by executing the same command in an Execute Shell, but after building the project (works fine) and then executing de command:

    @./tst_testgui -xunitxml > testresult.xml@

    I get the following message in Jenkins:

    QXcbConnection: Could not connect to display
    Aborted (core dumped)
    Build step ‘Execute shell’ marked build as failure
    Finished: FAILURE

    Does somebody know what could be the problem?

    I’m running Jenkins (for the moment) on my localhost and I don’t know if I have a graphic server.
    Where can I check if I’m using a graphic server in Jenkins?

    BTW: There is an empty testresult.xml generated in de workspace folder.

    Grtz. Niels

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nielske87
      wrote on last edited by
      #2

      The GuiTest I made is an example project from Qt itself and looks like this:
      @#include <QString>
      #include <QStringList>
      #include <QtTest>
      #include <QLineEdit>

      #include <QApplication>
      #include <QTextEdit>
      #include <QtGui>
      #include <QPushButton>
      #include <QVBoxLayout>
      #include <QMessageBox>

      class TestGui : public QObject
      {
      Q_OBJECT

      private slots:
      void testGui();

      };

      void TestGui::testGui()
      {
      QLineEdit lineEdit;
      QTest::keyClicks(&lineEdit, "hello world");
      QCOMPARE(lineEdit.text(), QString("hello world"));
      }

      QTEST_MAIN(TestGui)

      #include "tst_testgui.moc"@

      The output in QtCreator after running looks like this:

      ********** Start testing of TestGui **********
      Config: Using QTest library 5.0.2, Qt 5.0.2
      PASS : TestGui::initTestCase()
      PASS : TestGui::testGui()
      PASS : TestGui::cleanupTestCase()
      Totals: 3 passed, 0 failed, 0 skipped
      ********* Finished testing of TestGui *********

      When I change:
      @QTEST_MAIN(TestGui)@

      In:
      @QTEST_APPLESS_MAIN(TestGui)@

      The output in QtCreator looks like this:

      ********* Start testing of TestGui *********
      Config: Using QTest library 5.0.2, Qt 5.0.2
      PASS : TestGui::initTestCase()
      QFATAL : TestGui::testGui() QWidget: Must construct a QApplication before a QPaintDevice
      FAIL! : TestGui::testGui() Received a fatal error.
      Loc: [Unknown file(0)]
      Totals: 1 passed, 1 failed, 0 skipped
      ********* Finished testing of TestGui *********
      The program has unexpectedly finished.

      But the error in Jenkins is different now:

      + ./tst_testgui -xml
      Aborted (core dumped)
      Build step 'Execute shell' marked build as failure
      Finished: FAILURE

      Does anybody have an idea?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You are using GUI elements so you have to use QTEST_MAIN.

        When running your application from Jenkins, are you sure that it can find all libraries and plugins ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nielske87
          wrote on last edited by
          #4

          I think it does, because I can build and compile the project via Jenkins and I managed to make an UnitTest using CppUnit via the JUnit-plugin in an other project with (almost) the same configuration and that works perfect.

          Via the terminal I can exucte the program (tst_testgui) but not with Jenkins.

          Thnx for the fast response!

          EDIT: I'm not using a plugin at the moment. I'm only using shell commands.

          EDIT2: When try to execute the program via Jenkins from my home directory I get the same output as before:
          + /home/hotracodev/workspace/Focus/Experiment/TutorialGuiTest/tutorialGuiTest/tst_testgui
          QXcbConnection: Could not connect to display
          Aborted (core dumped)
          Build step 'Execute shell' marked build as failure
          Finished: FAILURE

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Yes you are: Qt 5's platform plugin which is using xcb in your case.

            I don't know jenkins but you could try to see if sets somehow the environment variables before doing a test and if so how does it differ from your console environment variables

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Nielske87
              wrote on last edited by
              #6

              I managed to solve my problem.

              The problem was in the configuration of Jenkins.
              I needed to use an X-server on my Jenkins machine to run my GUI programs.

              #SOLVED

              A 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Great you found out !

                Can you update your thread's title to solved ? So other forum users may know a solution has been found :)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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