简体   繁体   English

用Qt Creator在调试模式下编译一段代码

[英]Compile a piece of code in debug mode with Qt Creator

I am showing you my problem.我正在向你展示我的问题。 I'm creating an application in Qt Creator for a university project.我正在 Qt Creator 中为一个大学项目创建一个应用程序。 As you can see in the code below, I inserted two 'cout' inside a method just because they were useful to me to check that the program worked, this means that they have no real function.正如你在下面的代码中看到的,我在一个方法中插入了两个“cout”,只是因为它们对我检查程序是否有效很有用,这意味着它们没有真正的功能。 After viewing it, the professor delegated me to do it in debug mode with #IFDEF so that that portion of the code containing the 'cout' is visible only to the programmer and not to a hypothetical client.在查看之后,教授委托我使用 #IFDEF 在调试模式下执行此操作,以便包含“cout”的那部分代码仅对程序员可见,而对假设的客户端不可见。 I hope I have explained my problem fairly well, I thank anyone who can help me.我希望我已经很好地解释了我的问题,感谢任何可以帮助我的人。 Consider that in this type of thing I am quite novice.考虑到在这种类型的事情上我是新手。 Thanks谢谢

You have to use preprocessor macro.您必须使用预处理器宏。 The correct one for qt creator is QT_DEBUG . qt creator 正确的是QT_DEBUG Your code should look like this:您的代码应如下所示:

void BankAccount::addTransaction(Transaction* t){
    if(t->getType()==0 && actualAccountBalance < t->getTransactionValue()) {

#ifdef QT_DEBUG
        cout<<"Unable to add transaction: insufficient balance to make the requested withdrawal!"<<endl;
#endif

        ; // empty command, because of empty if
   }

   else if(find(transactions.begin(),transactions.end(),t) != transactions.end()) {

#ifdef QT_DEBUG
        cout<<"This transaction has already been added!"<<endl;
#endif

        ; // empty command, because of empty if

    }

    else{
        transactions.push_back(t);
        assignID(t);
        actualAccountBalance = calculateAccountBalance();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM