Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Issue with testing librairies



  • Hello everyone,

    After creating a librairy i want to test it in an other console application but as soon as i call a fonction from the librairy the result is an empty console where it is only written press <Entry> to close the window...

    I did a small example to test including a librairy and i have no problem doing it.

    Where this issue can come from ?

    Thank you in advance for any help.

    [Moved to General and Desktop ~kshegunov]


  • Qt Champions 2019

    @soufsouf How exactly do you test? It is completely unclear from your description! Does the function from the library which you call print anything?



  • @jsulm

    yes i am printing the result of the fonction called.

    I built a library called Util: libUtil.a where you have for example this fonction :
    int StrToInt(const UtilString& aString)
    {
    int num = aString.toInt();

    if(aString.indexOf(".") != -1)
    {
        num = RoundToInt(aString.toDouble());
    
    }
    return num;
    

    }

    and when i call this function in the main of the test project (in which i included the Library):

    UtilString num1ToStr = IntToStr(num1,true,5);
    std::cout << "Le resultat de 'num1ToStr.IntToStr(num1,true)' est: " << num1ToStr.toStdString()<< endl;

    i have always the console with nothing on it.

    In an other hand i did a small example with a fonction that print hello and increase the value of an int by +1 and it works just fine.

    thank you in advance for your time.


  • Qt Champions 2019

    @soufsouf Try to add std::flush:

    std::cout << "Le resultat de 'num1ToStr.IntToStr(num1,true)' est: " << num1ToStr.toStdString()<< endl << std::flush;
    

    Also can you show your main function where you call the library function?



  • in my main :
    #include "Util.h"
    #include <iostream>
    using namespace std;

    int main(int argc, char *argv[])
    {

    QCoreApplication a(argc, argv);
     int num1=52;
     UtilString chaine1="toto "; //(UtilString is define in my librairy)
     std::cout << "La chaine creee par chaine1= toto  est:" <<chaine1.toStdString() << endl; //this works just fine 
     
       UtilString num1ToStr;
      num1ToStr = IntToStr(num1,true,5); //when  i call IntToStr() nothing works anymore even the beginning
       std::cout << "Le resultat de 'num1ToStr.IntToStr(num1,true)' est: " << num1ToStr.toStdString()<< endl; 
    

    return a.exec();
    }


  • Qt Champions 2019

    @soufsouf said in Issue with testing librairies:

    when i call IntToStr() nothing works anymore even the beginning

    Can you show content of IntToStr?



  • int StrToInt(const UtilString& aString)
    {
    int num = aString.toInt();
    if(aString.indexOf(".") != -1)
    {
    num = RoundToInt(aString.toDouble());
    }
    return num;
    }


  • Qt Champions 2019

    @soufsouf IntToStr not StrToInt



  • @jsulm sorry

    UtilString IntToStr(int aValue, bool signPart,int integerPart)
    {
    UtilString s="";

    int intpart=abs(aValue);
    
    if(signPart) s+=((aValue>=0)?"+":"-");
    
    {
        UtilString ss;
    
        if(integerPart>0)
        {
            ss = UtilString("%1").arg(intpart,integerPart);
            ss.replace(' ','0');
        }
        else
        {
            ss = UtilString("%1").arg(intpart);
        }
        s+=ss;
    }
    

    return s;

    }


  • Qt Champions 2019

    @soufsouf If you comment out everything in IntToStr and just return an empty string, does it work then?



  • @jsulm no i already did it (but i did it again) no problem during the compilation but the execution give an empty console without any error message :/


  • Qt Champions 2019

    @soufsouf It could be toStdString() from your UtilString, you should check it



  • @jsulm if i hide this line: std::cout << "Le resultat de 'num1ToStr.IntToStr(num1,true)' est: " << num1ToStr.toStdString()<< endl; the beginning of the main is not printed in the console because of the IntToStr() call that is why it can't be something related to the printing ! i has been 3 days now that i am dealling with this issue do not know where to search.


  • Qt Champions 2019

    @soufsouf Did you try to debug step-by-step? Put a break point at the first line in IntToStr().



  • @jsulm I Can not explain why but when you asked me to debug a file in my librairy i changed from release to Debug the compiler of my Library project
    And then it worked !!!!
    Since my main.cpp to test the project is in Debug mode also i thought you have to be in the same mode in both ( Library and Test ) but when both are in release mode it doesn't work.

    Whatever thank you for your indications it'a good step.


Log in to reply