Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Integrate Qt in Application for Debug/Simulation (without qmake?)

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 505 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon_2001
    wrote on 13 Aug 2018, 19:36 last edited by
    #1

    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?

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Aug 2018, 21:42 last edited by
      #2

      Hi,

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon_2001
        wrote on 17 Aug 2018, 14:46 last edited by
        #3

        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>   
        #else 
        #include <iostream>
        #endif
        
        int main (void) {         
        
          //some calculations (which leds should be on)
          int leds = 5 * 10; 
        
          #ifndef DEBUG
           DDRB  = 0xFF;             
           PORTB = leds;     
          #else       
           std::cout << "These leds are high: " << leds << '\n'; 
          #endif
        
           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
        
        #avr
        MCU        := atmega328p
        PROGRAMMER := arduino
        PORT       := -P /dev/ttyUSB0
        BAUD       := -b  57600
        F_CPU      := 16000000
        
        #Compiler
        CXX       := avr-g++
        LDFLAGS   :=
        CXXFLAGS  := -Wall -std=c++11 -c
        
        # Commands
        REMOVE := rm -r -f
        
        #Directories
        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
        
        upload:
        	avrdude -p $(MCU) $(PORT) $(BAUD) -c $(PROGRAMMER) -U flash:w:$(BINDIR)/$(TARGET).hex:i
        
        size:
        	avr-size --mcu=$(MCU) -C --format=avr $(BINDIR)/$(TARGET).elf
        
        clean:
        	$(REMOVE) $(OBJDIR)
        	$(REMOVE) $(BINDIR)
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Aug 2018, 19:38 last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          13 Aug 2018, 19:36

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved