Abstract. In the context of ubiquitous and pervasive computing, publish/subscribe middleware is gaining momentum due to its loosely coupled communication scheme. In this paper we present Q, a publish/subscribe service conceived to operate in the context of mobile ad hoc networks. With Q, the overlay network that routes events from publishers to subscribers dynamically adapts itself to the changing topology by means of cross-layer interaction. Q also supports content-based filtering of events through mobile code: subscribers can specify in detail the notifications they wish to receive by defining proper filter classes, then binary code of filters is exchanged during runtime by participating nodes.