Important: Please read the Qt Code of Conduct -

Integrate Qt in Application for Debug/Simulation (without qmake?)

  • Hello,

    I already have some pieces of code for an arduino. I would like to visualize some of the calculated things as kind of a debug modus. So qt should not run beside the arduino!
    The user have the choice to compile it for arduino or for Computer with qt.

    At the moment, I just have some terminal output as the debug modus. So I wrote a makefile, which supports make and make upload for arduino and make debug for Terminal output. How could I integrate Qt? Normally, we have a .pro file generating a new makefile ... is it possible to write my own makefile for qt? Or can I call the generated makefile from my other makefile?


  • Lifetime Qt Champion


    Do you mean you want to:

    1. Build and upload your code to the arduino
    2. Build the exact same code as a Qt application to do some stuff but not use the arduino at all

    Is that correct ?

  • I think so.

    Of course my code uses macros to comment out arduino specific things, which could not run under x86_64 .

    A simple example

    #ifndef DEBUG
    #include <avr/io.h>   
    #include <iostream>
    int main (void) {         
      //some calculations (which leds should be on)
      int leds = 5 * 10; 
      #ifndef DEBUG
       DDRB  = 0xFF;             
       PORTB = leds;     
       std::cout << "These leds are high: " << leds << '\n'; 
       while(1) ;
       return 0;                 

    This is just a small useless example for illustration. In my real code I want the debug information (std::cout) to be visualized with qt and the qt code will only use the data from the arduino code and will be more seperated (adaptern pattern).

    Folder Structure

    • MyProject
      • bin
      • obj
      • src
        • debug
          • SomeQtCode.h
        • SomeArduinoCode.h
      • Makefile

    In my Makefile there should be two options

    make -> compiles everything for arduino (without qt classes of course) ... obj files in obj folder, bin files in bin folder (works perfect)
    make debug -> compiles everything for x86_64 (with qt files) ... obj files in obj folder, bin files in bin folder. Additionally it sets the DEBUG macro.

    But as we compile qt with qmake (which creates a makefile), my makefile should probably include the created makefile from qt? And it would also be great if I could specify that object/moc files come into the obj folder ....

    My Makefile currently

    TARGET := Hexapod
    MCU        := atmega328p
    PROGRAMMER := arduino
    PORT       := -P /dev/ttyUSB0
    BAUD       := -b  57600
    F_CPU      := 16000000
    CXX       := avr-g++
    LDFLAGS   :=
    CXXFLAGS  := -Wall -std=c++11 -c
    # Commands
    REMOVE := rm -r -f
    SRCDIR := src
    OBJDIR := obj
    BINDIR := bin
    # Files
    cppfiles := $(wildcard $(SRCDIR)/*.cpp)
    objects  := $(subst $(SRCDIR)/, $(OBJDIR)/, $(cppfiles:.cpp=.o))
    .Phony: all debug arduino install size clean
    default all: arduino
    debug: CXXFLAGS += -D DEBUG=1
    debug: CXX = g++
    debug: $(BINDIR)/$(TARGET)
    arduino: LDFLAGS += -Os -mmcu=$(MCU) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
    arduino: CXXFLAGS += -Os -mmcu=$(MCU) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -D F_CPU=$(F_CPU)
    arduino: $(BINDIR)/$(TARGET).hex
    # Debug
    $(BINDIR)/$(TARGET): $(objects)
    	mkdir -p $(@D)
    	$(CXX) $(LDFLAGS) -o $@ $^
    $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
    	mkdir -p $(@D)
    	$(CXX) $(CXXFLAGS) -o $@ $<
    # Arduino
    $(BINDIR)/$(TARGET).elf: $(objects)
    	mkdir -p $(@D)
    	$(CXX) $(LDFLAGS) -o  $@ $^
    $(BINDIR)/$(TARGET).hex: $(BINDIR)/$(TARGET).elf
    	avr-objcopy -O ihex -j .data -j .text $(BINDIR)/$(TARGET).elf $(BINDIR)/$(TARGET).hex
    	avrdude -p $(MCU) $(PORT) $(BAUD) -c $(PROGRAMMER) -U flash:w:$(BINDIR)/$(TARGET).hex:i
    	avr-size --mcu=$(MCU) -C --format=avr $(BINDIR)/$(TARGET).elf
    	$(REMOVE) $(OBJDIR)
    	$(REMOVE) $(BINDIR)

  • Lifetime Qt Champion

    Just to sum up and be sure we are talking about the same thing. You would like to run and debug your arduino code on your desktop as if it was running on the target and be able to build the same code and run in on the target. Correct ?

Log in to reply