Important: Please read the Qt Code of Conduct -

How to use Qt methods outside Qt Creator

  • Hello,
    I don't have much experience in that field yet, please don't be annoyed by my simple question.

    I work on a project in c++ without Qt, and without the Qt Creator (I prefer vim). Now I want to debug my code by drawing some output, therefor I want to use the Qt library.
    Is it possible to write a class in the Qt Creator using the Qt libraries, which should draw some data for me, and use this class in a project outside of the Qt creator and without any dependencies?

    I'm glad to get any helpful link or answer from you! Thanks.

  • Lifetime Qt Champion

    If you use qt classes you will get some dependencies.
    Depending on what you use of course.

    It is possible to static link so there is no external dlls/so
    but that requires license or open source project.

    But if just for debug. you can just use #defines and "make" options so that the final product won't need any Qt libraries.

  • Thank you for your answer, honestly I'm not even sure what exactely I should google for right now. Do you have any links for me? That would be a great help.

    Or do you think other graphic libraries than Qt fit better for my purpose?

  • Lifetime Qt Champion

    Hi if you explain what u want to draw, then I might have ideas.
    I use GNUPLOt myself for many things but all it depends on what u want to draw :)

  • @mrjj Sorry, I should have explained myself better. I want to draw a matrix of numbers in a rectangle, each pixel representing one number. Simply said I get a bitmap as input, and my program will detect the edges. The output is a matrix, the higher numbers of the matrix represent the edges and they should be drawn in white, while lower numbers will be drawn darker.

  • Lifetime Qt Champion

    well, that is pretty custom so not
    easy to do with std plotter.

    But if it is only for debug, it will be quite some work for getting it drawn
    you could just output to ascii table and just give them a number for "darkness"

    1 ( 100) | 3 (44) | 4 (255)
    4 ( 120) | 9 (44) | 2 (255)
    5 ( 140) | 3 (44) | 3 (255)
    7 ( 150) | 3 (44) | 4 (255)

    or something like that?

    If you are hooked on really drawing it,
    Make a default Qt GUI and use the other c++ code as
    utility. Meaning Qt is the test program and the
    pure C++ is the engine doing the work.
    As long as u dont use Qt feature in those .cpp / classes, it remains pure.

    But, if you are brand new to Qt, there will be some learning to draw it.
    Its not so much code. but some.

    you could try
    Its command line and you could just call it from your program to produce an image.

  • @mrjj thanks a lot for your help! I don't want to use a terminal in the end but really a custom window to show my output, so I try to not use the terminal and therefor no ascii table.

    I already worked quite a bit with qt, so I don't have a problem writing a solution inside the qt creator. What I would wish for is to write a static function "drawImage( Matrix)" that uses Qt to create a simple widget showing the image. Is there a way to use that function outside the Qt environment?

    I will take a closer look at ImageMagick, although I knew that before and I had the feeling it is difficult to implement in a C++ project.

  • Lifetime Qt Champion

    Im not 100% sure I understand the following
    " is there a way to use that function outside the Qt environment?"

    If you create a Qt program, it can be used outside Creator.

    But it will need the Qt libraries to work. So for it to have a window
    and show your output, it will need Qt. As those are Qt widgets.

    So not sure what you are asking about?

    If u mean to use a Qt function in your other c++, you could create a library that uses Qt and export a function drawImage( Matrix) that can do what u like.
    But if you want a window so bad, why not just make a Qt application ?
    Its will be same dependencies as a library.

    ImageMagick would be able to create and plot on image and even show it just
    by running the command lines tools. but it would not be integrated in your app as such.

  • Sorry for the late response, I managed to solve my problem without Qt, just in case someone stumbles upon this post.
    There is a simple library that can solve visual tasks. It is not as powerfull as Qt, but for small applications as I needed SFML provides enough functionality.
    Still thanks for all the help.

  • Lifetime Qt Champion

    Ok super.
    SFML is cool.
    Please mark as solved if possible.

Log in to reply