Qt 使用qDebug会导致google测试无法运行

Qt 使用qDebug会导致google测试无法运行,qt,qt5,qt-creator,googletest,Qt,Qt5,Qt Creator,Googletest,我正在尝试使用QT Creator的google测试。每当我尝试运行调用使用qDebug的函数的测试时,某些测试将不会运行(0通过,0失败,无错误)。如果我删除qDebug并使用cout之类的工具,测试将正常运行。运行所有测试或单独运行它们都有相同的问题。如果我调试测试,它将运行到完成,它似乎不会挂起任何东西 我有一个被构建为共享库的类,它是一个带有按钮的简单主窗口。点击按钮只是增加一个计数器。我将这个库添加到我的google测试项目中 主窗口 #ifndef MAINWINDOWLIB_H #

我正在尝试使用QT Creator的google测试。每当我尝试运行调用使用qDebug的函数的测试时,某些测试将不会运行(0通过,0失败,无错误)。如果我删除qDebug并使用cout之类的工具,测试将正常运行。运行所有测试或单独运行它们都有相同的问题。如果我调试测试,它将运行到完成,它似乎不会挂起任何东西

我有一个被构建为共享库的类,它是一个带有按钮的简单主窗口。点击按钮只是增加一个计数器。我将这个库添加到我的google测试项目中

主窗口

#ifndef MAINWINDOWLIB_H
#define MAINWINDOWLIB_H

#include "MainWindowLib_global.h"
#include <QMainWindow>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MAINWINDOWLIB_EXPORT MainWindowLib : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindowLib(QWidget *parent = nullptr);
    ~MainWindowLib();
    int getCounter();

private:
    Ui::MainWindow *ui;
    int counter = 0;

public slots:
    void button1Pressed();
};

#endif // MAINWINDOWLIB_H

不使用qDebug时测试全部通过:

将这两个函数放回qDebug时,只运行两个测试:

当我尝试单独运行测试时,按钮按下和GetCount测试将不会运行。如果我调试它们,它们就会运行并通过

我是否为qt应用程序设置了错误的测试

#include "mainwindowlib.h"
#include "ui_mainwindowLib.h"

#include <iostream>

#include <QDebug>

MainWindowLib::MainWindowLib(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->pushButton, &QPushButton::clicked, this, &MainWindowLib::button1Pressed);
}

MainWindowLib::~MainWindowLib()
{
    delete(ui);
}

int MainWindowLib::getCounter()
{
//    qDebug() << "Counter is: " << this->counter;
    return this->counter;
}

void MainWindowLib::button1Pressed()
{
    this->counter++;
//    qDebug() << "Counter is: " << this->counter;
    std::cout << "Counter is: " << this->counter << std::endl;
}

TEST_F(TestClass1, dummyTest1)
{
    ASSERT_EQ(1, 1);
}

TEST_F(TestClass1, testGetCount)
{
    int argc = 0;
    char *argv[1] = {NULL};

    QApplication a(argc, argv);
    MainWindowLib myWindow;

    int count = myWindow.getCounter();
    ASSERT_EQ(count, 0);
}

TEST_F(TestClass1, testButtonPressed)
{
    int argc = 0;
    char *argv[1] = {NULL};

    QApplication a(argc, argv);
    MainWindowLib myWindow;

    emit myWindow.button1Pressed();
    int count = myWindow.getCounter();

    ASSERT_EQ(count, 1);
}

TEST_F(TestClass1, dummyTest2)
{
    ASSERT_EQ(4, 4);
}