this post was submitted on 04 Feb 2025
10 points (81.2% liked)

Programming

18039 readers
37 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
 

How can i connect imagine a Qt interface(C++) with a logic in java. I feel like I've should know this already but I don't, I know there are API but I don't want to do it,

More context: They told me to write an aplication, game such as 4 connect, battleship or that kind of games, so I've thought to make the "snakes and ladders", i knew how i could do the 2 thinks separately but I don't know how to connect the frontend with backend, even tho I knew the games should works with threads. So I don't know if I could do it with the interface in Qt, because the main porpouse of the practice is to work with threads

top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 8 points 3 hours ago

Think about why you're wanting to do this. Is there a material benefit you'll get from splitting your codebase like so? Enough to overcome the fact that you've split your codebase into two very different languages?

When you're going between languages like this, you either need some kind of communication protocol (e.g. JRPC, TCP, or maybe something home cooked) or you need a stable ABI to allow the programs to talk to each other directly.

My point is, you probably don't want to do what you're trying to do. Unless you have a really good reason, pick one language and stick with it.

[–] [email protected] 2 points 2 hours ago

i second the comment that you need to consider why you want to do this. You generally need a pretty good reason to split your codebase into multiple languages.

As far as actually doing it, you have a ton of different options, some of which have been mentioned here. Some i can think of off the top of my head:

  • create a library (dll or so file or the like)
  • set up a web server and use communication protocols (either web socket or rest API or the like)
  • use a 3rd party communication/messaging framework like MQ or kafka or something
  • create your own method of communication. Something like reading and writing to a file on disk, or a database and acting on the information plopped in

basically every approach is going to require you to come up with some sort of API that the two work together through, though, an API in the generic sense is basically a shared contract two disconnected pieces of code use to communicate.

[–] [email protected] 2 points 3 hours ago

A socket, pipe, or shared memory region?

A network connection to localhost?

Running the backend as a child process of the frontend, and using standard io?

[–] mcmodknower 1 points 2 hours ago (1 children)

Does the frontend need to be written in C++, or can you write the frontend in java too (in a JFrame from the javax.swing package)?

[–] brian 4 points 2 hours ago

or if you really wanted qt, using java qt bindings: https://github.com/OmixVisualization/qtjambi