Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QtDesigner crash in debug mode #847

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Libs/Core/Testing/Cpp/ctkLoggerTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// CTK includes
#include <ctkLogger.h>
#include <ctkUtils.h>

// STL includes
#include <cstdlib>
Expand All @@ -43,6 +44,12 @@ int ctkLoggerTest1(int argc, char * argv [] )
logger.error("logger.error");
logger.fatal("logger.fatal");

// This should log a warning "Assertion `5 == 6` failed ..."
CTK_SOFT_ASSERT(5 == 6);

// This should not log anything
CTK_SOFT_ASSERT(8 == 8);

return EXIT_SUCCESS;
}

15 changes: 15 additions & 0 deletions Libs/Core/ctkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,27 @@
// Qt includes
#include <QStringList>
#include <QDateTime>
#include <QDebug>

// STD includes
#include <vector>

#include "ctkCoreExport.h"

/// This macro can be used instead of Q_ASSERT to warn developers
/// when some assumption fails. CTK_SOFT_ASSERT behavior differs
/// in two key aspects: (1) it only logs a warning (instead of terminating
/// the application) and (2) the message is always logged (instead of
/// ignoring the check in release builds).
#define CTK_SOFT_ASSERT(condition) do \
{ \
if (! (condition) ) \
{ \
qWarning() << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__; \
} \
} while (false)

namespace ctk {
///
/// \ingroup Core
Expand Down
5 changes: 3 additions & 2 deletions Libs/Widgets/ctkMatrixWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// CTK includes
#include "ctkMatrixWidget.h"
#include "ctkDoubleSpinBox.h"
#include "ctkUtils.h"

// Qt includes
#include <QDebug>
Expand Down Expand Up @@ -238,7 +239,7 @@ void ctkMatrixWidgetPrivate::updateGeometries()
bool lastColumn = (j==(ccount-1));
int newWidth = lastColumn ? lastColWidth : colWidth;
this->Table->setColumnWidth(j, newWidth);
Q_ASSERT(this->Table->columnWidth(j) == newWidth);
CTK_SOFT_ASSERT(this->Table->columnWidth(j) == newWidth);
}
// rows
const int rcount = q->rowCount();
Expand All @@ -249,7 +250,7 @@ void ctkMatrixWidgetPrivate::updateGeometries()
bool lastRow = (i==(rcount-1));
int newHeight = lastRow ? lastRowHeight : rowHeight;
this->Table->setRowHeight(i, newHeight);
Q_ASSERT(this->Table->rowHeight(i) == newHeight);
CTK_SOFT_ASSERT(this->Table->rowHeight(i) == newHeight);
}
this->Table->updateGeometry();
}
Expand Down