Pervasive computing environments are populated by a large number of heterogeneous and dynamic resources, encompassing devices, services and information sources. This number is set to radically increase in the future; as a result, a mobile device will be able to contact a large number of service providers and sensors that will enable it to perform any task at hand. Moreover, interaction with these services and sensors will be made possible by means of various components, some located on the mobile device, some available for download from remote hosts. We refer to services, sensors and components as resources. In this paper we present Q-CAD, a resource discovery framework that enables pervasive computing applications to discover and select the resource(s) best satisfying the user needs, taking the current execution context and quality-of-service (QoS) requirements into account. The available resources are screened, so that only those suitable to the current execution context of the application will be considered; the shortlisted resources are then evaluated against the QoS needs of the application, and a binding is established to the best available. The paper illustrates how we encode context and QoS information, gives details of the Q-CAD model and of its mapping onto a component-based architecture, and it finally reports on the implementation and on the experimental results.