  Quantum state transfer into a memory, state shuttling over long distances via
a quantum bus, and high-fidelity readout are important tasks for quantum
technology. Realizing these tasks is challenging in the presence of realistic
couplings to an environment. Here, we introduce and assess protocols that can
be used in cavity QED to perform high-fidelity quantum state transfer and fast
quantum nondemolition qubit readout through Hamiltonian engineering. We show
that high-fidelity state transfer between a cavity and a single qubit can be
performed, even in the limit of strong dephasing due to inhomogeneous
broadening. We generalize this result to state transfer between a cavity and a
logical qubit encoded in a collective mode of a large ensemble of $N$ physical
qubits. Under a decoupling sequence, we show that inhomogeneity in the ensemble
couples two collective bright states to only two other collective modes,
leaving the remaining $N-3$ single-excitation states dark. Moreover, we show
that large signal-to-noise and high single-shot fidelity can be achieved in a
cavity-based qubit readout, even in the weak-coupling limit. These ideas may be
important for novel systems coupling single spins to a microwave cavity.
